OpenSSLRSA.h

来源:互联网 发布:网络协议基础知识 编辑:程序博客网 时间:2024/06/08 16:55
#ifndef QL_HEADER_OPENSSL_RSA_H
#define QL_HEADER_OPENSSL_RSA_H


#include <string>
using namespace std;


#include <openssl/rsa.h>


class COpenSSLRSA
{
public:
COpenSSLRSA(void);
~COpenSSLRSA(void);


public:
//RSA公钥加密
std::string EncodeRSAPubKeyData(bool bIsBase64 = true);


//RSA公钥解密
std::string DecodeRSAPubKeyData(bool bIsBase64 = true);


//RSA私钥加密
std::string EncodeRSAPriKeyData(bool bIsBase64 = true);


//RSA私钥解密
std::string DecodeRSAPriKeyData(bool bIsBase64 = true);


// 创建秘钥对文件和秘钥对象
void BuildKey();


// 读取公钥-文件
bool ReadPubRSAByFile();


// 读取私钥-文件
bool ReadPriRSAByFile();


// 读取公钥-内存
bool ReadPubRSAByMem(bool bNeedFormat = true);


// 读取私钥-内存
bool ReadPriRSAByMem(bool bNeedFormat = true);


private:
// 取得秘钥文件内容
void GetKeyFileContent(string filename, string& sKeyText);


// 取得错误信息
void PrintErrMsg(int nRet, char* sFuncName);


public:
// 错误消息
char m_sErrMsg[1024];


// 私钥密码
char m_sPriKeyPwd[256];


// 原文、密文
string m_sText;
string m_sCryptText;


// 公钥、私钥(文本)
string m_sPubKey;
string m_sPriKey;


// 公钥、私钥(文件名)
string m_sPubKeyFile;
string m_sPriKeyFile;


private:
// 公钥、私钥(RSA对象)
RSA* m_pRSAPub; 
RSA* m_pRSAPri;



};


#endif
0 0