Cryptography App Block: Problem

Topics: Cryptography Application Block
Nov 15, 2007 at 9:35 AM
Hi,
I am using RijndaelManaged for a symmetric encryption-decryption. The scenario is as the following:
First: I ecrypt a password text with the statements:

//using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;
string encryptedContents = Cryptographer.EncryptSymmetric("RijndaelManaged", token);
return encryptedContents;

// The encrypted password is stored in a table column (varchar), SQL server 2000

Second: After retrieving password from the column, I decrypt using the statements:

string decryptedContents = Cryptographer.DecryptSymmetric("RijndaelManaged", token);
return decryptedContents;

decryption fails, throwing the exception: System.Security.Cryptography.CryptographicException: Unable to decrypt data.

I am sure that everything is configured properly and in place!

Any clues?

Yousef
Nov 15, 2007 at 9:40 AM
Edited Nov 15, 2007 at 9:43 AM
Encryption works perfectly, but decryption fails!
Sometimes I get the exception: System.Security.Cryptography.CryptographicException: Length of the data to decrypt is invalid
Nov 15, 2007 at 1:10 PM
Hi,

Some questions:
  • Are you encrypting and decrypting in the same machine?
  • Are you using the token variable for both the plaintext and the cryptotext?
  • Does the crypto quickstart work for you?

Regards,
Fernando
Nov 15, 2007 at 1:21 PM
Edited Nov 15, 2007 at 1:22 PM
Sorry for bothering guys!

I've just figured out the problem: the SP that adds the user info, and specifically the encrypted password truncated it due to the parameter size, which was smaller than required!

Yousef