Reputation: 1674
I am trying to use AES encryption with encryption in one program and decryption in another. I have working code that encrypts the file but I need to extract the key to use in the other program to decrypt.
When I do this:
string key = String.Empty;
byte[] aesKey;
using (var aes = Aes.Create())
{
aesKey = aes.Key;
key = Convert.ToBase64String(aes.Key);
}
and use aesKey in my encrypt it works. When I try to convert from Base64 string to Byte[] it doesn't seem to work, It doesn't end up with the same bytes. How do you convert?
string sKey = "LvtZELDrB394hbSOi3SurLWAvC8adNpZiJmQDJHdfJU=";
aesKey = System.Text.Encoding.UTF8.GetBytes(sKey);
Upvotes: 0
Views: 431
Reputation: 56536
There is a corresponding From
method that you should use.
byte[] aesKey = Convert.FromBase64String(sKey);
Upvotes: 2