我正在尝试使用 system.security.cryptography 使用 3DES 解密,但是在提供加密散列进行解密或提供纯文本进行加密时会引发异常。
错误:指定的密钥对于此算法无效。
private byte[] KEY_192;
private byte[] IV_192;
public string DecryptTripleDES(string value)
{
if (value != "")
{
TripleDESCryptoServiceProvider cryptoProvider = new TripleDESCryptoServiceProvider();
MemoryStream ms = new MemoryStream(Convert.FromBase64String(value));
CryptoStream cs = new CryptoStream(ms, cryptoProvider.CreateDecryptor(this.KEY_192, this.IV_192), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cs);
return sr.ReadToEnd();
}
return value;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text=textBox1.Text.Trim().Replace("'", "");
string password = DecryptTripleDES(textBox1.Text);
textBox1.Text = password;
}