openssl RSA 内存读取密钥
2016-10-08 15:51
711 查看
主要注意一下密钥的格式
#include <openssl/pem.h> #include <openssl/err.h> bool CEncipher::CreatePubKey() { BIO* bp = NULL; string strPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmm9GRVbi5+myHYztzOyWvMdo1\ 4b0fwRF3va9A8bd19oW9ZUCpALVIC4d4I1Zvkfcgnpvswf/DOHD9umT+pevmwICF\ /mU8LNe/MT8kGh0IAIHdJVrXw/2TEWCVEgFlFfloWzCNmzOcx4BH8yIw50RjG1ED\ 5Fl5QKFrirgcU11IhQIDAQAB"; int nPublicKeyLen = strPublicKey.size(); for(int i = 64; i < nPublicKeyLen; i+=64) { if(strPublicKey[i] != '\n') { strPublicKey.insert(i, "\n"); } i++; } strPublicKey.insert(0, "-----BEGIN PUBLIC KEY-----\n"); strPublicKey.append("\n-----END PUBLIC KEY-----\n"); char *chPublicKey = const_cast<char *>(strPublicKey.c_str()); if ((bp = BIO_new_mem_buf(chPublicKey, -1)) == NULL) { printf("BIO_new_mem_buf failed!\n"); return false; } pPubKey_ = PEM_read_bio_RSA_PUBKEY(bp, NULL, NULL, NULL); if (NULL == pPubKey_) { ERR_load_crypto_strings(); char errBuf[512]; ERR_error_string_n(ERR_get_error(), errBuf, sizeof(errBuf)); printf("load public key failed[%s]\n", errBuf); return false; } BIO_free_all(bp); return true; }
相关文章推荐
- openssl RSA 内存读取密钥
- 使用Qt调用openssl 从内存中读取私钥对RSA密文进行解密
- java读取openssl生成的RSA密钥
- openssl——从内存中读取RSA公钥并加密 以及 "PRNG not seeded" error message 的解决办法
- RSA读取密钥——使用openssl编程
- 学习使用OpenSSL生成并使用RSA密钥对
- Windows下RSA密钥生成工具openssl
- Linux 下使用openSSL 生成RSA密钥对
- JKS密钥对生成与读取及RSA工具类
- C#中用RSA算法生成公钥和私钥 openssl RSA密钥的生成与配置
- Linux(openSSL)上RSA密钥生成和使用(java)
- openssl对rsa密钥的管理用法
- 保存openssl中RSA密钥对
- Windows下RSA密钥生成工具openssl
- 生成RSA密钥、保存到文件、从文件读取、加密、解密等操作。
- OPENSSL RSA加密同一程序多次加载密钥会加密解密出错
- openssl0.9.8编程生成RSA密钥对(探讨篇)(windows XP SP2+VC6.0)【转】
- openssl生成rsa密钥对和密钥格式转换
- openssl rsa密钥格式的问题,解决了php和c++协同开发的密钥格式问题
- openssl0.9.8编程生成RSA密钥对(探讨篇)(windows XP SP2+VC6.0)【转】