String to byte array and back
To convert a string to a byte array, you can use this method:
public static byte[] StringToByteArray(string s)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
return encoding.GetBytes(s);
}
To convert it back to a string:
public static string ByteArrayToString(byte[] b)
{
System.Text.ASCIIEncoding encode = new System.Text.ASCIIEncoding();
return encode.GetString(b);
}