This commit is contained in:
2023-04-14 14:56:01 +08:00
parent b1422411a2
commit 1abb153d76
16 changed files with 1388 additions and 133 deletions

View File

@@ -9,6 +9,11 @@ namespace LenheartBase
class CBASE64
{
public:
// 生成RSA密钥结构
static void* __genKey(int nBits);
// 生成密钥对输出为PEM字符串
static bool genKeyStrings(std::string& strPrivateKeyPEMString, std::string& strPublicKeyPEMString);
// 执行BASE64编码操作
static std::string encode(const std::string& str);
@@ -20,8 +25,20 @@ namespace LenheartBase
static std::string RsaPriDecrypt(const std::string& cipher_text, const std::string& pri_key);
// 执行RSA私匙加密操作
static std::string RsaPriEncrypt(const std::string& clear_text, const std::string& pri_key);
private:
// 使用PEM私钥字符串加密
static bool encryptByPrivatePEMString(const std::string& strIn, std::string& strOut, const std::string& strKeyPEMString);
// 使用PEM公钥字符串加密
static bool encryptByPublicPEMString(const std::string& strIn, std::string& strOut, const std::string& strKeyPEMString);
// 使用PEM公钥字符串解密
static bool decryptByPublicPEMString(const std::string& strIn, std::string& strOut, const std::string& strKeyPEMString);
// 使用RSA执行加密或解密
static bool __encryptOrDecrypt(const std::string& strIn, std::string& strOut, const void* pRSA, const void* pFunc, bool bEncrypt);
private:
// 分组编码
static int __encode(unsigned char* pDest, const unsigned char* pSrc, size_t nSrcLen);
@@ -29,7 +46,6 @@ namespace LenheartBase
static int __decode(unsigned char* pDest, const unsigned char* pSrc, size_t nSrcLen);
private:
// 编解码转换表
static unsigned char s_encTable[];
static unsigned char s_decTable[];