我试图用c++作为语言,OpenSSL作为密码提供程序,在windows中编写一个山茶花解密程序。当试图执行代码时,我得到以下错误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[] = "\xd4\xc5\x91\xad\xe5\x7e\x56\x69\xcc\xcd\xb7\x11\xcf\x02\xec\xbc";
unsigned char camcipher[] = "\x00\xf7\x41\x73\x04\x5b\x99\xea\xe5\x6d\x41\x8e\xc4\x4d\x21\x5c";
const unsigned char camkey[] = "\x92\x63\x88\x77\x9b\x02\xad\x91\x3f\xd9\xd2\x45\xb1\x92\x21\x5f\x9d\x48\x35\xd5\x6e\xf0\xe7\x3a\x39\x26\xf7\x92\xf7\x89\x5d\x75";
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;
}密钥和IV使用python3中的urandom生成,然后使用PyCryto库camellia创建密码文本。
为了避免填充,我故意把密码文本放在16字节处。我真的不知道我做错了什么。任何帮助都会很棒。
明文应改为“一条秘密消息”。
发布于 2022-05-25 22:47:35
看起来您需要声明unsigned char plaintext;为unsigned char plaintext[17];,否则您将覆盖未初始化的内存。
https://stackoverflow.com/questions/72384300
复制相似问题