Encryption and Decryption
-
HI ALL, I am using the following code for Decrtption public static string Decrypt(string xxxxx) { RijndaelManaged RijndaelCipher = new RijndaelManaged(); string Password = "srinu"; byte[] EncryptedData = Convert.FromBase64String(xxxxx); byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString()); //Making of the key for decryption PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt); //Creates a symmetric Rijndael decryptor object. ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16)); MemoryStream memoryStream = new MemoryStream(EncryptedData); //Defines the cryptographics stream for decryption.THe stream contains decrpted data CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read); byte[] PlainText = new byte[EncryptedData.Length]; int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length); memoryStream.Close(); cryptoStream.Close(); //Converting to string string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount); return DecryptedData; } It is showing me an error "An exception of type 'System.FormatException' occurred in .DLL but was not handled in user code Additional information: Invalid length for a Base-64 char array." in the Line "byte[] EncryptedData = Convert.FromBase64String(xxxxx);" Plz help me solve this ASAP.
-
HI ALL, I am using the following code for Decrtption public static string Decrypt(string xxxxx) { RijndaelManaged RijndaelCipher = new RijndaelManaged(); string Password = "srinu"; byte[] EncryptedData = Convert.FromBase64String(xxxxx); byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString()); //Making of the key for decryption PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt); //Creates a symmetric Rijndael decryptor object. ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16)); MemoryStream memoryStream = new MemoryStream(EncryptedData); //Defines the cryptographics stream for decryption.THe stream contains decrpted data CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read); byte[] PlainText = new byte[EncryptedData.Length]; int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length); memoryStream.Close(); cryptoStream.Close(); //Converting to string string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount); return DecryptedData; } It is showing me an error "An exception of type 'System.FormatException' occurred in .DLL but was not handled in user code Additional information: Invalid length for a Base-64 char array." in the Line "byte[] EncryptedData = Convert.FromBase64String(xxxxx);" Plz help me solve this ASAP.
srinivaskonijeti wrote:
Additional information: Invalid length for a Base-64 char array." in the Line "byte[] EncryptedData = Convert.FromBase64String(xxxxx);"
It should be clear, the xxxxx string you pass in, is NOT BASE64 encoded.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)
((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))