【发布时间】:2021-04-03 19:11:45
【问题描述】:
我想将 .txt 文件中的多行输出定向到该 encrypt() 函数。 .txt 文件包含我要加密的文件的地址。代码可以编译,但没有加密。我正在使用 EVP_aes_256_cbc() 进行加密。我做错了什么?
int encrypt(unsigned char* plaintext, int plaintext_len, unsigned char* key, unsigned char* iv, unsigned char* ciphertext);
int decrypt(unsigned char* ciphertext, int ciphertext_len, unsigned char* key, unsigned char* iv, unsigned char* plaintext);
int main() {
unsigned char key[16];
RAND_bytes(key, sizeof(key));
unsigned char iv[16];
RAND_bytes(iv, sizeof(iv));
std::ifstream file("C:\\Users\NULL\source\repos\xFolder\YFolder\\test.txt");
std::string str;
while (std::getline(file, str))
{
int encrypt(unsigned char* str, int plaintext_len, unsigned char* key,unsigned char* iv, unsigned char* ciphertext);
}
【问题讨论】:
-
除了 Mike 的回答中指出的错误之外,
encrypt和decrypt看起来是错误的。固定:int encrypt(const unsigned char* plaintext, int plaintext_len, const unsigned char* key, const unsigned char* iv, unsigned char* ciphertext);和int decrypt(const unsigned char* ciphertext, int ciphertext_len, const unsigned char* key, const unsigned char* iv, unsigned char* plaintext); -
@Ted 感谢您的输入,但根据您的建议,我的代码无法编译,错误 LNK2001 unresolved external symbol "int __cdecl encrypt(unsigned char const *,int,unsigned char const *,unsigned char const *,unsigned char *)" (?encrypt@@YAHPEBEH00PEAE@Z)
-
这些函数不是你自己定义的或者是从 OpenSSL 主页的 C 示例中复制过来的吗?
-
Ted 我没有从 OpenSSL 页面复制。谢谢,你帮了大忙。
-
不客气!函数签名看起来与OpenSSL wiki 中的示例非常相似,并且可能存在相同的问题(不正确的
const应该在哪里)所以我想你可以同时更改声明和定义(除非它们被定义在某个地方你不能改变它)。
标签: c++ encryption openssl aes