开发者

Invalid key size for 3DES

开发者 https://www.devze.com 2023-04-05 05:07 出处:网络
i am trying to use 3DES decryption using the system.security.cryptography but it throws an exception upon giving an encrypted hash for decryption or a plain text for encryption.

i am trying to use 3DES decryption using the system.security.cryptography but it throws an exception upon giving an encrypted hash for decryption or a plain text for encryption.

error: specified key is not valid size for this algorithm.

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(开发者_Python百科object sender, EventArgs e)
    {   
        textBox1.Text=textBox1.Text.Trim().Replace("'", "");


        string password = DecryptTripleDES(textBox1.Text);
        textBox1.Text = password;

    }


You need to assign values to KEY_192 and IV_192.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号