使用OpenSSL的山茶花时访问违规



我试图在windows中使用c++作为语言和OpenSSL作为加密提供程序编写山茶花解密程序。当尝试执行代码时,我得到以下错误Exception thrown at 0x00007FFABB31AEF8 (libcrypto-3-x64.dll) in Lab8.exe: 0xC0000005: Access violation reading location 0x0000000000000028.

代码是:

#include <iostream>
#include <windows.h>
#include <openssl/camellia.h>
#include <openssl/conf.h>
#include <openssl/err.h>
#include <string.h>
#pragma warning(disable : 4996)
unsigned char iv[] = "xd4xc5x91xadxe5x7ex56x69xccxcdxb7x11xcfx02xecxbc";
unsigned char camcipher[] = "x00xf7x41x73x04x5bx99xeaxe5x6dx41x8exc4x4dx21x5c";
const unsigned char camkey[] = "x92x63x88x77x9bx02xadx91x3fxd9xd2x45xb1x92x21x5fx9dx48x35xd5x6exf0xe7x3ax39x26xf7x92xf7x89x5dx75";
unsigned char plaintext;
CAMELLIA_KEY finalkey;
int main()
{
Camellia_set_key(camkey, 256, &finalkey);
Camellia_cbc_encrypt(camcipher, (unsigned char*)plaintext, CAMELLIA_BLOCK_SIZE,&finalkey, iv, 0);
std::cout << plaintext;
}

Key和IV是使用python3中的随机生成的,然后使用pycrypto库camellia创建密文。

我故意将密文保留为16字节以避免填充。我真的不确定我做错了什么。任何帮助都会很棒的。

明文应该是"秘密消息">

看起来您需要将unsigned char plaintext;声明为unsigned char plaintext[17];,否则您将覆盖未初始化的内存。

最新更新