简体   繁体   English

System.Security.Cryptography.CryptographicException:'输入数据不是一个完整的块。'

[英]System.Security.Cryptography.CryptographicException: 'The input data is not a complete block.'

I am new to decryption, and trying to decrypt like ColdFusion was in the previous version.我是解密新手,尝试像以前版本中的 ColdFusion 一样解密。 I am getting this error, and not sure what it means.我收到此错误,不知道它是什么意思。

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);

It means what it says.这意味着它所说的。 In CBC mode the plaintext is first padded to a full number of blocks.在 CBC 模式下,明文首先填充到完整数量的块中。 This always happens for PKCS#7 padding.这总是发生在 PKCS#7 填充中。 Then each block of plaintext is encrypted sequentially, using the previously encrypted block as vector;然后将每个明文块依次加密,以之前加密的块为向量; this block is XOR'ed with the plaintext.此块与明文进行异或运算。

The initial vector (IV) needs to be provided, and for CBC mode it needs to be fully unpredictable to an attacker.需要提供初始向量 (IV),并且对于 CBC 模式,它需要对攻击者完全不可预测。 That generally means that it should consist of randomized bytes.这通常意味着它应该由随机字节组成。 A constant, encoded string doesn't meet this requirement.恒定的编码字符串不满足此要求。

Of course, the result consists of ciphertext blocks.当然,结果由密文块组成。 Now if the decryption routine encounters a number of bytes that is not a multiple of the block size, you'll get the error.现在,如果解密例程遇到的字节数不是块大小的倍数,您将收到错误消息。 That means that either the message has additional data, or it hasn't been encoded correctly.这意味着消息要么有额外的数据,要么没有正确编码。 It may also mean that a different mode than CBC was used, or even CBC with ciphertext stealing.这也可能意味着使用了与 CBC 不同的模式,甚至是带有密文窃取的 CBC。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Security.Cryptography.CryptographicException:“输入数据不是一个完整的块。” 在 stream.Close() - System.Security.Cryptography.CryptographicException: "The input data is not a complete block." on stream.Close() System.Security.Cryptography.CryptographicException: &#39;输入数据不是一个完整的块。&#39; C# - System.Security.Cryptography.CryptographicException: 'The input data is not a complete block.' C# System.Security.Cryptography.CryptographicException 输入数据不是一个完整的块 - System.Security.Cryptography.CryptographicException The input data is not a complete block System.Security.Cryptography.CryptographicException:句柄无效 - System.Security.Cryptography.CryptographicException: The handle is invalid TwilioRequestValidator 中的瞬态 System.Security.Cryptography.CryptographicException - Transient System.Security.Cryptography.CryptographicException in TwilioRequestValidator System.Security.Cryptography.CryptographicException:参数不正确 - System.Security.Cryptography.CryptographicException: The parameter is incorrect System.Security.Cryptography.CryptographicException:'Cryptography_OAEPDecoding' - System.Security.Cryptography.CryptographicException: 'Cryptography_OAEPDecoding' System.Security.Cryptography.CryptographicException:系统找不到指定的文件 - System.Security.Cryptography.CryptographicException: The system cannot find the file specified System.Security.Cryptography.CryptographicException:RSACryptoserviceProvider中的长度错误 - System.Security.Cryptography.CryptographicException : Bad length in RSACryptoserviceProvider 给出错误密码时出现System.Security.Cryptography.CryptographicException - System.Security.Cryptography.CryptographicException when wrong password given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM