我有以下查询.可以任何人请建议我一个解决方案.
我是第一次加密和解密文件.
我使用命令通过命令提示符加密文件:
openssl enc -aes-256-cbc -in file.txt -out file.enc -k "key value" -iv "iv value"
Run Code Online (Sandbox Code Playgroud)
我必须以编程方式解密它.所以我已经为它编写了程序,但它抛出了以下错误:
./exe_file enc_file_directory
...
error: 06065064: digital envelope routines: EVP_DecryptFInal_ex: bad decrypt: evp_enc.c
Run Code Online (Sandbox Code Playgroud)
下面的程序将输入作为目录路径并搜索加密文件".enc"并尝试将其解密读入缓冲区.
码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/conf.h>
#include <libxml/globals.h>
void handleErrors(char *msg)
{
{
ERR_print_errors_fp(stderr);
printf("%s", msg);
abort();
}
}
void freeMemory(char *mem)
{
if (NULL != mem)
{
free(mem);
mem = NULL;
}
}
/* Function to …Run Code Online (Sandbox Code Playgroud)