今天用System.Security.Cryptography加密。使用了AesManaged,报错:填充无效,无法移除。分析是解密失败,密文损坏,或者KEY,IV不正确。
using (AesManaged aesAlg = new AesManaged())
{
aesAlg.Key = Encoding.Unicode.GetBytes("password");
aesAlg.IV = aesAlg.Key; using (ICryptoTransform decryptor = aesAlg.CreateDecryptor())
{
return decryptor.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
} }