簡體   English   中英

使用 OpenSSL 的 Camellia 時訪問沖突

[英]Access Violation when using OpenSSL's Camellia

我正在嘗試使用 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 庫山茶花創建密文。

我故意將密文保留為 16 字節以避免填充。 我真的不確定我做錯了什么。 任何幫助都是極好的。

明文應為“秘密消息”

看起來您需要聲明unsigned char plaintext; unsigned char plaintext[17]; ,否則您將覆蓋未初始化的內存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM