Dercyption错误“填充无效且无法删除” [英] Dercyption Error “Padding is invalid and cannot be removed”
本文介绍了Dercyption错误“填充无效且无法删除”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
这是我的解密代码,我想要解密这个密码,但问题是它出错了
Hi All,
This is my decryption code i want to decrypt this password but problem is that it is giving an error
static void Main(string[] args)
{
string str = Decrypt("vASqxLq4dmegE0l3K8T7ng==", "");
Console.WriteLine(str);
Console.ReadKey();
}
private const string IV = "MazenTech.com.pk";
private const int keysize = 128;
public static string Decrypt(string cipherText, string passPhrase)
{
byte[] plainTextBytes = null;
int decryptedByteCount = 0;
try
{
byte[] IVBytes = Encoding.ASCII.GetBytes(IV);
byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null);
byte[] keyBytes = password.GetBytes(keysize / 8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, IVBytes);
MemoryStream memoryStream = new MemoryStream(cipherTextBytes);
CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
plainTextBytes = new byte[cipherTextBytes.Length];
decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length); // error this line
memoryStream.Close();
cryptoStream.Close();
}
catch (Exception ex)
{
Console.WriteLine("Your Password is Incorrect....");
}
return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
}
如何解决它请帮帮我。谢谢你提前:))
How to fix it please help me.Thanks in Advance:)
推荐答案
这篇关于Dercyption错误“填充无效且无法删除”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文