Note that there are some explanatory texts on larger screens.

plurals
  1. POAES Encryption Error: Padding is invalid and cannot be removed
    primarykey
    data
    text
    <p>Can anyone help me on the below code, error is padding is invalid and cannot be removed. I am searching all over SO and applied all their suggestions, but still padding is invalid. I am using NET-2.0</p> <p>Below is my code</p> <pre><code>static public String AES_encrypt(String Input) { string AES_Key = "PSVJQRk9QTEpNVU1DWUZCRVFGV1VVT0ZOV1RRU1NaWQ="; string AES_IV = "YWlFLVEZZUFNaWlhPQ01ZT02qWU5HTFJQVFNCRUJZVA="; var aes = new RijndaelManaged(); aes.KeySize = 256; aes.BlockSize = 256; aes.Padding = PaddingMode.PKCS7; aes.Key = Convert.FromBase64String(AES_Key); aes.IV = Convert.FromBase64String(AES_IV); var encrypt = aes.CreateEncryptor(aes.Key, aes.IV); byte[] xBuff = null; using (var ms = new MemoryStream()) { using (var cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write)) { byte[] xXml = Encoding.UTF8.GetBytes(Input); cs.Write(xXml, 0, xXml.Length); } xBuff = ms.ToArray(); } String Output = Convert.ToBase64String(xBuff); return Output; } static public String AES_decrypt(String Input) { string AES_Key = "PSVJQRk9QTEpNVU1DWUZCrOFGV1VVT0ZOV1RRU1NaWQ="; string AES_IV = "YWlFLVEZZUFNaWlhPQ01ZT02qWU5HTFJQVFNCRUJZVA="; RijndaelManaged aes = new RijndaelManaged(); aes.KeySize = 256; aes.BlockSize = 256; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; aes.Key = Convert.FromBase64String(AES_Key); aes.IV = Convert.FromBase64String(AES_IV); var decrypt = aes.CreateDecryptor(); byte[] xBuff = null; using (var ms = new MemoryStream()) { using (var cs = new CryptoStream(ms, decrypt, CryptoStreamMode.Write)) { byte[] xXml = Convert.FromBase64String(Input); cs.Write(xXml, 0, xXml.Length); } xBuff = ms.ToArray(); } String Output = Encoding.UTF8.GetString(xBuff); return Output; } </code></pre> <p>I am thinking the issues here is the AES_encrypt, because if I passed an encrypted string from PHP to my project, AES_decrypt will successfully decrypt it. However, whenever I use AES_encrypt, AES_decrypt is throwing error.</p> <p>Any help would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload