博坦 AES-256,32 位初始矢量
Botan AES-256, 32 bit InitialVector
我目前有一些代码可以与LibTomCrypt库一起使用,但不能与Botan一起使用(我正在尝试将其转换为Botan)。
我的(工作)LibTomCrypt代码:
// read the initial vector
unsigned char iv[0x20];
fseek(inputFile, 0x20, SEEK_SET);
fread(iv, 0x20, 1, inputFile);
// call ctr_start
res = ctr_start(0, iv, key, 0x20, 0, 0, &ctr);
if (res == 0)
{
printf("decrypting data...n");
// read the encrypyted data
unsigned char cipheredText[0x3A8];
fread(cipheredText, 0x3A8, 1, inputFile);
// decrypt the data
unsigned char uncipheredText[0x3A8];
if (ctr_decrypt(cipheredText, uncipheredText, 0x3A8, &ctr) != 0)
{
fclose(inputFile);
printf("ERROR: ctr_decrypt did not return 0n");
return -1;
}
if (ctr_done(&ctr) != 0)
{
fclose(inputFile);
printf("ERROR: ctr_done did not return 0n");
return -1;
}
printf("writing decrypted data...n");
// get the decrypted path
char *decPath = concat(fileName, ".dec", 4);
// write the decrypted data to disk
FILE *outFile = fopen(decPath, "w");
fwrite(uncipheredText, 0x3A8, 1, outFile);
fclose(outFile);
}
else
{
printf("ERROR: ctr_start did not return 0n");
}
如您所见,我的初始向量 (IV) 的大小为 0x20 (32)。我不知道为什么这会与这个库一起使用,但我去了该方法,它似乎与 LibTomCrypt 中的"blocklen"有关。
无论如何,这就是我试图用 Botan 库做的事情:
// get the iv
t1Stream->setPosition(0x20);
BYTE rawIV[0x20];
t1Stream->readBytes(rawIV, 0x20);
// get the encrypted data
t1Stream->setPosition(0x40);
BYTE cipheredText[0x3A8];
t1Stream->readBytes(cipheredText, 0x3A8);
// setup the keys & IV
Botan::SymmetricKey symKey(key, 0x20);
Botan::InitializationVector IV(rawIV, 0x20);
// setup the 'pipe' ?
Botan::Pipe pipe(Botan::get_cipher("AES-256/CBC/NoPadding", symKey, IV, Botan::DECRYPTION));
但它一直在"get_cipher"的召唤下抛出这个:
terminate called after throwing an instance of 'Botan::Invalid_Key_Length'
what(): Botan: AES-256 cannot accept a key of length 32
如果我确实将 IV 大小更改为 16,那么它确实可以正常工作,但由于 IV 不正确而无法处理东西。
另外,更改加密代码中的 IV 大小不是一种选择。
我们无法真正看到您正在使用的密码模式。如果是 Rijndael-256,则块大小为 256 位。如果不是,那么随机数很可能被库在某个地方切断 - 在这种情况下,很可能只使用前 128 位。
也就是说,代码将永远不起作用,因为您在第一个示例中使用计数器模式加密,在另一个示例中使用 CBC 模式加密。
相关文章:
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- QT:AES-256-CBC 根据 PHP 代码在C++中加密/解密
- 博坦加载现有的 RSA 私钥
- AES 256-cbc 加密C++使用 OpenSSL
- 使用 AES-256 CBC 加密文本文件
- 如何使用用户定义的密码初始化AES-256密钥
- 如何通过AES-256-CBC使用密码代替密钥和IV加密文件
- 在Qt中使用博坦加密大文件时如何获得加密/解密进度
- AES 256 加密 - 相当于 Java 的 Qt
- 在 AES 256 加密++中获取十六进制加密字符串
- AES 256 encryption in C++ and Qt 5
- 博坦 AES-256,32 位初始矢量
- 解密AES-256加密文件不起作用
- AES、128 和 256 密钥长度无效
- <iosfwd> 在安卓工作室下构建博坦时没有这样的文件?
- Problems with CryptoPP C++ AES-256+Base64
- 是否有aes 256与CBC加密在ubuntu/linux/unix
- 生成AES (AES-256)查找表
- AES-256 使用 ECB 操作模式的 OpenSSL 库进行加密
- AES 256 位加密在 pdf 文件中