Using the function from: http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx
public static byte[] encryptStringToBytes_AES(string plainText, byte[] Key, byte[] IV)
As you can see it returns a byte array, I want to convert the byte array to a string.
How can I convert it from a byte array to string and visa versa?
If you don't care how it's stored, an easy way is to use:
Convert byte array into string: Convert.ToBase64String(YourByteArray)
and
Convert string into byte array: Convert.FromBase64String(YourString)
.
This will give a concise, printable ASCII representation of the byte array.
这可以帮助你很多,即将转换为十六进制格式,但可能非常有用如何将字节数组转换为十六进制字符串,反之亦然?
While using Rijndael Encryption i faced this problem, it returns encrypted byte[] (array), Convert byte[] to string;
myStringVariable= Convert.ToBase64String(myEncryptedByteArray);
Convert string to byte[];
byte[] bytes = Convert.FromBase64String(myStringVariable);
For more about Rijndael
Cheers !!!
System.Text.Encoding.ASCII.GetString(bytes);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.