【发布时间】:2021-04-22 04:09:40
【问题描述】:
我是解密新手,尝试像以前版本的 ColdFusion 一样解密。我收到了这个错误,不知道是什么意思。
string cipherText = "text";
//this is from coldfusion
String key = "key";
//var AES_algorithm = "AES";
//var AES_encoding = "hex";
//<cfset Result = #Decrypt(val, AES_Private_Key, AES_algorithm, AES_encoding)#>
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException("plainText");
//not sure what this is?
String iv = "1020304050607080";
if (key == null || key.Length <= 0)
throw new ArgumentNullException("Key");
if (iv == null || iv.Length <= 0)
throw new ArgumentNullException("IV");
byte[] bytearraytodecrypt = Convert.FromBase64String(cipherText);
AesCryptoServiceProvider keydecrypt = new AesCryptoServiceProvider();
keydecrypt.BlockSize = 128;
keydecrypt.KeySize = 128;
keydecrypt.Key = System.Text.Encoding.UTF8.GetBytes(key);
keydecrypt.IV = System.Text.Encoding.UTF8.GetBytes(iv);
keydecrypt.Padding = PaddingMode.PKCS7;
keydecrypt.Mode = CipherMode.CBC;
ICryptoTransform crypto1 = keydecrypt.CreateDecryptor(keydecrypt.Key, keydecrypt.IV);
byte[] returnbytearray = crypto1.TransformFinalBlock(bytearraytodecrypt, 0, bytearraytodecrypt.Length);
crypto1.Dispose();
return System.Text.Encoding.UTF8.GetString(returnbytearray);
【问题讨论】:
-
请查看我编辑中的代码格式,以供以后的帖子参考。 Stack Overflow 使用反引号字符进行代码格式化,3 用于块,1 用于段落内。
-
我认为我做得对。下次我会更加努力的。
标签: c# encryption