views:

247

answers:

3

Hi,

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?

A: 
System.Text.Encoding.ASCII.GetString(bytes);
Jimmy
ASCII is a 7-bit code. It isn't going to work on 8-bit AES ciphertext.
erickson
+11  A: 

If you don't care how it's stored, an easy way is to use: Convert.ToBase64String() and Convert.FromBase64String(). This will give a concise, printable ASCII representation of the byte array.

Talljoe
+2  A: 

This can help you a lot, is about to converting into Hex format but can be very usefull http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa-in-c

backslash17