呵呵呵呵呵

萝莉有三好,柔体 轻音 易推倒。女神有三宝,干嘛 呵呵 去洗澡。宅男有三好:Dota 基友 破电脑。


openssl rsa解密部分代码demo

openssl rsa解密部分代码demo

std::string DecodeRSAKeyFile( const std::string& strPemFileName, const std::string& strData )
    {
        if (strPemFileName.empty() || strData.empty())
        {
            assert(false);
            return "";
        }
        FILE* hPriKeyFile = NULL;
        if(fopen_s(&hPriKeyFile, strPemFileName.c_str(),"rb") || hPriKeyFile == NULL)
        {
            assert(false);
            return "";
        }
        std::string strRet;
        RSA* pRSAPriKey = RSA_new();
        if(PEM_read_RSAPrivateKey(hPriKeyFile, &pRSAPriKey, 0, 0) == NULL)
        {
            assert(false);
            return "";
        }
        int nLen = RSA_size(pRSAPriKey);
        char* pDecode = new char[nLen+1];

        int ret = RSA_private_decrypt(strData.length(), (const unsigned char*)strData.c_str(), (unsigned char*)pDecode, pRSAPriKey, RSA_PKCS1_PADDING);
        if(ret >= 0)
        {
            strRet = std::string((char*)pDecode, ret);
        }
        delete [] pDecode;
        RSA_free(pRSAPriKey);
        fclose(hPriKeyFile);
        CRYPTO_cleanup_all_ex_data();
        return strRet;
    }

更多内容:

openssl RSA加密部分代码demo
使用openssl对网络传输的数据加密方法
ie 浏览器设置为不缓存
openssl rsa密钥生成示例
openssl rsa中PEM和BIGNUM公钥转换示例

本文链接地址:http://www.hehehehehe.cn/i/722.html