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
nik_san12
NA
1
0
PKCS7 padding is invalid and cannot be removed
Dec 23 2003 6:23 PM
Hi All, I get this Cryptography exception while decrypting a querystring. Any Help in this will be appreciated. Thanks Here is my code for encryption/decryption. using System; using System.IO; using System.Text; using System.Security.Cryptography; namespace lweb { ///
/// Summary description for Encryption. ///
public class Encryption { byte [] key; byte [] IV; byte [] inputByteArray; RijndaelManaged myR = new RijndaelManaged(); public Encryption() { myR.GenerateKey(); myR.GenerateIV(); key = myR.Key; IV = myR.IV; } public string Decrypt(string stringToDecrypt) { inputByteArray = new byte[stringToDecrypt.Length]; ICryptoTransform decryptor = myR.CreateDecryptor(key, IV); try { inputByteArray = Convert.FromBase64String(stringToDecrypt); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); ASCIIEncoding encoding = new ASCIIEncoding(); return encoding.GetString(ms.ToArray()); } catch(System.Exception ex) { throw ex; } } public string Encrypt(string stringToEncrypt) { inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt); ICryptoTransform encryptor = myR.CreateEncryptor(key, IV); try { MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); return Convert.ToBase64String(ms.ToArray()); } catch(System.Exception ex) { throw ex; } } } } I am using this for Encryption, which works fine string userModURL = "updateProfile.aspx?FN="; string test = oES.Encrypt(fn.Text.ToString()); userModURL = userModURL + test; Decryption which doesnt works string ff = Request.QueryString["FN"]; string dd = ff.Replace(" ", "+"); string ee = oES.Decrypt(dd); The decrypt page works fine within the same page, i.e., if i encrypt and decrypt the strings on the same page.
Reply
Answers (
0
)
why datagrid_SelectedIndexChanged doesn't work the first time
How to select items in server side?