我只想用openSSL测试这三种模式的AES:128,192和256密钥长度,但我的解密文本与我的输入不同,我不知道为什么.此外,当我传递一个巨大的输入长度(比方说1024字节)时,我的程序显示core dumped...我的输入始终是相同的,但它无关紧要,至少目前如此.下面是代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
int main(int argc, char **argv)
{
int i;
int keylength;
printf("Give a key length [only 128 or 192 or 256!]:\n");
scanf("%d", &keylength);
/* generate a key with a given length */
unsigned char aes_key[keylength];
memset(aes_key, 0, sizeof(aes_key));
if (!RAND_bytes(aes_key, keylength))
{
exit(-1);
}
aes_key[keylength-1] = '\0';
int inputslength;
printf("Give an input's length:\n");
scanf("%d", &inputslength);
/* generate input with a given length */
unsigned char aes_input[inputslength+1];
memset(aes_input, '0', sizeof(aes_input)); …Run Code Online (Sandbox Code Playgroud)