0
超过16个字节,因此我有1622个字节长度的字节[],但我想解密这一切,但AES只有128位的块大小。 如果我尝试其分割为16个字节我得到这个异常块: System.Security.Cryptography.CryptographicException 附加信息:输入缓冲区包含的数据不足。它可以是rawDataArea%16!= 0?我怎样才能解密字节[]从AES
加密器:
aes256Alg = new AesManaged
{
Key = new byte[] {112,90,16,164,90,221,73,154,246,32,13,102,145,7,57,115,37,5,3,102,205,39,202,231,195,148,202,229,53,138,102,242},
Mode = CipherMode.CBC,
KeySize = 256,
BlockSize = 128,
Padding = PaddingMode.PKCS7,
IV = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
ICryptoTransform aes256Encryptor = aes256Alg.CreateEncryptor(aes256Alg.Key,aes256Alg.IV);
解密
AesManaged aes256AlgCBC;
aes256AlgCBC = new AesManaged
{
Key = new byte[] {190,151,28,108,241,101,254,174,16,11,87,84,239,140,239,85,195,25,78,192,105,109,95,128,160,146,123,31,190,188,181,216},
KeySize = 256,
Mode = CipherMode.CBC,
BlockSize = 128,
Padding = PaddingMode.PKCS7,
IV = new byte[] {199,114,91,241,148,90,133,166,13,52,142,187,101,125,81,73}
};
ICryptoTransform aes256CbcDecryptor = aes256AlgCBC.CreateDecryptor(aes256AlgCBC.Key, aes256AlgCBC.IV);
//byte[] rawDataArea = {0x00 .......} // Length of 1622 copied from hexeditor
List<Byte[]> dataAreaByteList = new List<byte[]>();
//Split the rawDataArea up to blocks of 16 bytes and then adding them to a list
//which later can be converted back to a big array
for (int i = 0; i < rawDataArea.Length; i += 16)
{
byte[] transformedBlock = new byte[] { };
aes128CbcDecryptor.TransformBlock(rawDataArea, i, (i += 16),transformedBlock,i);
dataAreaByteList.Add(transformedBlock);
}
字节数组的长度必须是16的因子。如果不是的话,这就是填充用武之地。 – ThePerplexedOne
如果你想使用'TransformBlock'风格的界面,你需要使用['TransformFinalBlock'(https://msdn.microsoft.com/en-us/library/system.security.cryptography.icryptotransform.transformfinalblock( v = vs.110).aspx),最后一块。它特别允许大块数据不等于整个块。 –