OpenSSL 编程 - RSA 加密解密
2010-06-02 11:08
549 查看
gcc -o rsa-decrypt rsa-decrypt.c -lcrypto![]() */ ![]() #include <openssl/rsa.h> ![]() ![]() #define MODULUS "C8FBCF21" ![]() #define PUBLIC_EXPONENT RSA_F4 ![]() #define PRIVATE_EXPONENT "97B55D7D" ![]() ![]() int main() ![]() { ![]() int ret, flen; ![]() BIGNUM *bnn, *bne; ![]() unsigned char in[] = {0x98, 0x79, 0xb2, 0x76}; ![]() unsigned char *out; ![]() ![]() bnn = BN_new(); ![]() bne = BN_new(); ![]() BN_hex2bn(&bnn, MODULUS); ![]() BN_set_word(bne, PUBLIC_EXPONENT); ![]() ![]() RSA *r = RSA_new(); ![]() r->n = bnn; ![]() r->e = bne; ![]() RSA_print_fp(stdout, r, 5); ![]() ![]() flen = RSA_size(r); ![]() out = (unsigned char *)malloc(flen); ![]() bzero(out, flen); ![]() ![]() printf("Begin decrypt... "); ![]() ret = RSA_public_decrypt(sizeof(in), in, out, r, RSA_NO_PADDING); ![]() if (ret < 0) ![]() { ![]() printf("Decrypt failed! "); ![]() return 1; ![]() } ![]() ![]() printf("Size:%d ", ret); ![]() printf("ClearText:%s ", out); ![]() ![]() free(out); ![]() RSA_free(r); ![]() return 0; ![]() } ![]() 解密: ![]() /* ![]() gcc -o rsa-decrypt rsa-decrypt.c -lcrypto ![]() */ ![]() #include <openssl/rsa.h> ![]() ![]() #define MODULUS "C8FBCF21" ![]() #define PUBLIC_EXPONENT RSA_F4 ![]() #define PRIVATE_EXPONENT "97B55D7D" ![]() ![]() int main() ![]() { ![]() int ret, flen; ![]() BIGNUM *bnn, *bne; ![]() unsigned char in[] = {0x98, 0x79, 0xb2, 0x76}; ![]() unsigned char *out; ![]() ![]() bnn = BN_new(); ![]() bne = BN_new(); ![]() BN_hex2bn(&bnn, MODULUS); ![]() BN_set_word(bne, PUBLIC_EXPONENT); ![]() ![]() RSA *r = RSA_new(); ![]() r->n = bnn; ![]() r->e = bne; ![]() RSA_print_fp(stdout, r, 5); ![]() ![]() flen = RSA_size(r); ![]() out = (unsigned char *)malloc(flen); ![]() bzero(out, flen); ![]() ![]() printf("Begin decrypt... "); ![]() ret = RSA_public_decrypt(sizeof(in), in, out, r, RSA_NO_PADDING); ![]() if (ret < 0) ![]() { ![]() printf("Decrypt failed! "); ![]() return 1; ![]() } ![]() ![]() printf("Size:%d ", ret); ![]() printf("ClearText:%s ", out); ![]() ![]() free(out); ![]() RSA_free(r); ![]() return 0; ![]() } |
相关文章推荐
- OpenSSL 编程 - RSA 加密解密
- OpenSSL 编程 - RSA 加密解密
- OpenSSL 编程 - RSA 加密解密
- C/C++使用openssl进行摘要和加密解密(md5, sha256, des, rsa)
- 利用openssl进行RSA加密解密
- 利用openssl进行RSA加密解密实例
- rsa 网站openssl加密解密 使用心得
- php openssl rsa 加密解密应用
- C/C++使用openssl进行摘要和加密解密(md5, sha256, des, rsa)
- OpenSSL 中 RSA 加密解密实现源码分析
- vs2010 c++ openssl rsa 加密解密 共用两种格式加密解密
- linux下使用openssl对文件RSA加密解密
- AES加密和解密——使用openssl编程
- openssl RSA非对称加密解密
- CryptoAPI与openssl RSA非对称加密解密(PKCS1 PADDING)交互
- 用openssl进行rsa的加密与解密(linux,C++版)
- openssl evp RSA 加密解密
- 用openssl进行rsa的加密与解密(linux,C++版)
- php openssl rsa 加密解密
- php基于openssl的rsa加密解密示例