加密啊啊啊

非常抱歉,我的错误。在openssl/aes.h中没有定义AES_ENCRYPT常量。实际上,在AES_cbc_encrypt函数中,并不需要传递一个参数来指定加密操作。

在AES_cbc_encrypt函数的定义中(定义在openssl/aes.h),它只接受一个名为encrypt的参数,该参数是一个整数值,用于指定是进行加密操作还是解密操作。具体而言,当encrypt为1时,表示执行加密操作;当encrypt为0时,表示执行解密操作。

下面是示例代码的修正版,去掉了AES_ENCRYPT参数的使用:

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>

#define KEY_SIZE 16

void encryptFile(const char* inputFile, const char* outputFile, const unsigned char* key) {
    FILE *inFile = fopen(inputFile, "rb");
    FILE *outFile = fopen(outputFile, "wb");
    
    if (inFile == NULL || outFile == NULL) {
        printf("Failed to open file.\n");
        return;
    }
    
    // 读取文件内容
    fseek(inFile, 0, SEEK_END);
    long fileSize = ftell(inFile);
    rewind(inFile);
    unsigned char* fileContent = (unsigned char*)malloc(fileSize);
    fread(fileContent, sizeof(unsigned char), fileSize, inFile);
    
    // 加密
    AES_KEY aesKey;
    AES_set_encrypt_key(key, KEY_SIZE * 8, &aesKey);
    
    unsigned char iv[AES_BLOCK_SIZE] = {0};  // 初始化向量
    
    unsigned char encryptedContent[fileSize];
    AES_cbc_encrypt(fileContent, encryptedContent, fileSize, &aesKey, iv, 1); // encrypt参数设置为1
    
    // 将加密后的内容写入文件
    fwrite(encryptedContent, sizeof(unsigned char), fileSize, outFile);
    
    // 释放资源
    free(fileContent);
    fclose(inFile);
    fclose(outFile);
    
    printf("Encryption complete.\n");
}

int main() {
    const char* inputFile = "input.txt";      // 待加密的文件名
    const char* outputFile = "encrypted.txt";  // 加密后的文件名
    unsigned char key[KEY_SIZE] = "aa12345678";  // 密钥
    
    encryptFile(inputFile, outputFile, key);
    
    return 0;
}
```

再次对我的错误表示抱歉,并感谢您的指正。

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值