用openssl库RSA加密解密
1 #include <stdio.h> 2 #include <openssl/rsa.h> 3 #include <openssl/pem.h> 4 #include <openssl/err.h> 5 6 //加密 7 int my_encrypt(const char *input, int input_len, char *output, int *output_len, const char *pri_key_fn) 8 { 9 RSA *p_rsa = NULL; 10 FILE *file = NULL; 11 int ret = 0; 12 13 if((file = fopen(pri_key_fn, "rb")) == NULL) 14 { 15 ret = -1; 16 goto End; 17 } 18 19 if((p_rsa = PEM_read_RSAPrivateKey(file, NULL,NULL,NULL )) == NULL) 20 { 21 ret = -2; 22 goto End; 23 } 24 25 if((*output_len = RSA_private_encrypt(input_len, (unsigned char*)input, (unsigned char*)output, p_rsa, RSA_PKCS1