#include <openssl/rsa.h>//构建RSA数据结构 bne =BN_new(); bnd =BN_new(); bnn =BN_new(); ret =BN_set_word(bne, e); BN_hex2bn(&bnd, PRIVATE); BN_hex2bn(&bnn, MODULUS);//准备输出的加密数据结构 flen= RSA_size(r);// - 11; encData= (unsigned char *)malloc(flen); bzero(encData, flen);//memset(encData, 0, flen);ret= RSA_public_decrypt(flen, encData, decData,r, RSA_NO_PADDING);

int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding);int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding);int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding);int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding);

RSA算法详解及C语言实现。一、RSA算法 :如果 a 不是 p 的倍数, 也不是 q 的倍数时, 则 a^(p-1) == 1 mod p (费马小定理) => a^(k(p-1)(q-1)) == 1 mod p a^(q-1) == 1 mod q (费马小定理) => a^(k(p-1)(q-1)) == 1 mod q 所以 p, q 均能整除 a^(k(p-1)(q-1)) - 1 => pq | a^(k(p-1)(q-1)) - 1 即 a^(k(p-1)(q-1)) == 1 mod pq => c == a^(k(p-1)(q-1)+1) == a mod pq.二、RSA 的安全性。