المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : convert to base 64 issue with AES encryption



C# Programming
08-12-2009, 06:46 AM
Hello,

new to encryption.

however i am using the following partial code to encrypt and decrypt and it works....




byte[] encrypted = encryptStringToBytes_AES(txtMessage.Text, myRijndael.Key, myRijndael.IV);



string decipheredText = decryptStringFromBytes_AES(encrypted, myRijndael.Key, myRijndael.IV);



so this is an MSDN example and it works!!! i get the same thing if i DONT manipulate the byte[] any.

now the fun parts....

i try to do this




byte[] encrypted = encryptStringToBytes_AES(txtMessage.Text, myRijndael.Key, myRijndael.IV);


string ciphertext = Encoding.UTF8.GetString(encrypted);

byte[] cipher = Convert.FromBase64String(ciphertext);



// Decrypt the bytes to a string.
string decipheredText = decryptStringFromBytes_AES(cipher, myRijndael.Key, myRijndael.IV);






as you can see i added 2 extra lines, and encoded to get back to a string. then converted to base 64 to get back to a byte []. YES i transmit the data in between those two lines but i made it simple to troubleshoot. this DOES NOT work..... i have tried diff encodings like UTF8 etc.

help!!

10 million dollars to the one who gets it working hahaha


thanks!