3

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?

SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • Possible duplicate of [How convert byte array to string](https://stackoverflow.com/questions/11654562/how-convert-byte-array-to-string) – peterh May 12 '19 at 16:54

4 Answers4

18

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.

shalin
  • 443
  • 4
  • 22
Talljoe
  • 14,593
  • 4
  • 43
  • 39
2

This can help you a lot, is about to converting into Hex format but can be very usefull How do you convert Byte Array to Hexadecimal String, and vice versa?

Community
  • 1
  • 1
backslash17
  • 5,300
  • 4
  • 31
  • 46
0

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 !!!

shalin
  • 443
  • 4
  • 22
0
System.Text.Encoding.ASCII.GetString(bytes);
Jimmy
  • 89,068
  • 17
  • 119
  • 137