使用openssl时访问违规
我正在尝试使用C ++作为语言在Windows中编写Camellia解密程序,然后将OpenSSL作为加密提供商。 我会在0x00007FFABB31AEF8(libcrypto-3-x64.dll)中获取以下错误在lab8.exe中获得的异常:0xc00000055:访问违规位置读取位置0x000000000000000028
尝试执行代码时,
#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库凸轮来创建密码文本。
我故意将密码文本放在16个字节上,以避免填充。我真的不确定我做错了什么。任何帮助都很棒。
明文应阅读“秘密消息”
I'm trying to write a camellia decryption program in windows using c++ as the language and OpenSSL as the cryptographic provider. When attempting to execute the code I get the following error Exception thrown at 0x00007FFABB31AEF8 (libcrypto-3-x64.dll) in Lab8.exe: 0xC0000005: Access violation reading location 0x0000000000000028.
The code is:
#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;
}
The Key and IV were generated using urandom from python3 and then used to create the cipher text using the PyCryto library camellia.
I purposefully left the cipher text at 16 Bytes to avoid padding. I'm really not sure what I'm doing wrong at all. Any help would be awesome.
The plaintext should read "a secret message"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您需要声明
无符号char plaintext;
为无符号char plaintext [17];
,否则,您会覆盖非初始化的内存。Looks like you need to declare
unsigned char plaintext;
to beunsigned char plaintext[17];
, otherwise you're overwriting uninitialized memory.