![](/img/trans.png)
[英]System.Security.Cryptography.CryptographicException: "The input data is not a complete block." on stream.Close()
[英]System.Security.Cryptography.CryptographicException: 'The input data is not a complete block.'
我是解密新手,嘗試像以前版本中的 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);
這意味着它所說的。 在 CBC 模式下,明文首先填充到完整數量的塊中。 這總是發生在 PKCS#7 填充中。 然后將每個明文塊依次加密,以之前加密的塊為向量; 此塊與明文進行異或運算。
需要提供初始向量 (IV),並且對於 CBC 模式,它需要對攻擊者完全不可預測。 這通常意味着它應該由隨機字節組成。 恆定的編碼字符串不滿足此要求。
當然,結果由密文塊組成。 現在,如果解密例程遇到的字節數不是塊大小的倍數,您將收到錯誤消息。 這意味着消息要么有額外的數據,要么沒有正確編碼。 這也可能意味着使用了與 CBC 不同的模式,甚至是帶有密文竊取的 CBC。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.