TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Premal
NA
1
0
AES Decryption problem
Jul 20 2007 4:10 AM
Here is the code: public static string Encrypt(string plainString, string password, string saltString) { byte[] plainBytes = Encoding.Unicode.GetBytes(plainString); byte[] saltBytes = Encoding.ASCII.GetBytes(saltString); PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(password, saltBytes); RijndaelManaged Cipher = new RijndaelManaged(); ICryptoTransform Encryptor = Cipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16)); MemoryStream mStream = new MemoryStream(); CryptoStream cStream = new CryptoStream(mStream, Encryptor, CryptoStreamMode.Write); cStream.Write(plainBytes, 0, plainBytes.Length); cStream.FlushFinalBlock(); byte[] captchaResult = mStream.ToArray(); mStream.Close(); cStream.Close(); return Convert.ToBase64String(captchaResult); } public static string Decrypt(string cipherString, string password, string saltString) { byte[] cipherBytes = Encoding.UTF8.GetBytes(cipherString); byte[] saltBytes = Encoding.ASCII.GetBytes(saltString); PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(password, saltBytes); RijndaelManaged Cipher = new RijndaelManaged(); ICryptoTransform Decryptor = Cipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16)); MemoryStream mStream = new MemoryStream(cipherBytes); CryptoStream cStream = new CryptoStream(mStream, Decryptor, CryptoStreamMode.Read); byte[] plainBytes = new byte[cipherBytes.Length]; int decrCount = cStream.Read(plainBytes, 0, plainBytes.Length); mStream.Close(); cStream.Close(); return Encoding.Unicode.GetString(plainBytes, 0, decrCount); } During decryption, I get the following error: "Length of the data to decrypt is invalid." on this line of code: int decrCount = cStream.Read(plainBytes, 0, plainBytes.Length); Please help. Thanx in advance.
Reply
Answers (
0
)
Is it normaliztion will reduces performence?
static menthods in interfaces