小编use*_*347的帖子

OpenSSL和AES

我正在使用OpenSSL lib并使用AES加密/解密获得非常奇怪的效果:如果我将更改加密消息中的某个字节并对其进行解密,我将看到原始消息的一部分,这不是假设的.这是源代码:

#include <openssl/evp.h> 
#include <string.h>

int do_crypt(void) 
{  
 int outlen, inlen;  
 FILE *in, *out;  
 in = fopen("in.txt", "r"); 
 out = fopen("out.txt", "w"); 
 unsigned char key[32];
 strcpy(key, "10000000000000000000000000000002"); 
 unsigned char iv[8];
 unsigned char inbuf[BUFSIZE], outbuf[BUFSIZE];  
 EVP_CIPHER_CTX ctx;  
 const EVP_CIPHER * cipher;    


 EVP_CIPHER_CTX_init(&ctx);   
 cipher = EVP_aes_256_cfb(); 
 EVP_EncryptInit(&ctx, cipher, key, 0); 

while(1) {                    
 inlen = fread(inbuf, 1, BUFSIZE, in);  
 if(inlen <= 0) break;  
 if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, inbuf, inlen)) return 0;  
 fwrite(outbuf, 1, outlen, out);  
 }    

if(!EVP_EncryptFinal(&ctx, outbuf, &outlen)) return 0;  
 fwrite(outbuf, 1, …
Run Code Online (Sandbox Code Playgroud)

c linux openssl cryptography aes

1
推荐指数
1
解决办法
1911
查看次数

标签 统计

aes ×1

c ×1

cryptography ×1

linux ×1

openssl ×1