string Salt = "Kosher", HashAlgorithm = "SHA1"; int PasswordIterations = 2; string InitialVector = "OFRna73m*aze01xY"; int KeySize = 256; if (string.IsNullOrEmpty(CipherText)) return ""; byte[] InitialVectorBytes = System.Text.Encoding.ASCII.GetBytes(InitialVector); byte[] SaltValueBytes = System.Text.Encoding.ASCII.GetBytes(Salt); byte[] CipherTextBytes = Convert.FromBase64String(CipherText); PasswordDeriveBytes DerivedPassword = new PasswordDeriveBytes(Password, SaltValueBytes, HashAlgorithm, PasswordIterations); byte[] KeyBytes = DerivedPassword.GetBytes(KeySize / 8); RijndaelManaged SymmetricKey = new RijndaelManaged(); SymmetricKey.Mode = CipherMode.CBC; byte[] PlainTextBytes = new byte[CipherTextBytes.Length]; int ByteCount = 0; using (ICryptoTransform Decryptor = SymmetricKey.CreateDecryptor(KeyBytes, InitialVectorBytes)) { using (MemoryStream MemStream = new MemoryStream(CipherTextBytes)) { using (CryptoStream CryptoStream = new CryptoStream(MemStream, Decryptor, CryptoStreamMode.Read)) { ByteCount = CryptoStream.Read(PlainTextBytes, 0, PlainTextBytes.Length); MemStream.Close(); CryptoStream.Close(); } } } SymmetricKey.Clear(); return System.Text.Encoding.UTF8.GetString(PlainTextBytes, 0, ByteCount);
ByteCount = CryptoStream.Read(PlainTextBytes, 0, PlainTextBytes.Length) this line as <br /> <br /> <br /> Padding is invalid and cannot be removed<br /> <br /> <br /> Any body know why error like this arising?<br /> <br /> Thanks in Advance
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)