基于OpenSSL的一些经常使用加密签名算法

目前包括:MD五、SHA5十二、DES、RSA加解密、RSA+MD5签名验证算法,在openssl基础上再进行封装,使用简单,头文件须要包含openssl库,能够使用vcpkg自动管理,省去繁琐的配置工程的过程。git

该RSA签名算法中,已将输入明文作了MD5处理。算法

注意RSA加密算法E,解密算法D,与RSA签名算法S,验证算法V,这里的EDSV互补相等,不要认为加密过程的E使用公钥,验证过程的V也使用公钥,就把二者混为一谈。函数

 

一看头文件就显得容易使用了工具

class COpenSSL
{
public:
	COpenSSL();
	~COpenSSL();

	// ---- md5摘要哈希 ---- // 
	void md5(const std::string &srcStr, std::string &encodedHexStr);

	// ---- sha256摘要哈希 ---- //  
	void sha256(const std::string &srcStr, std::string &encodedHexStr);

	// ---- des对称加解密 ---- //    
	// 加密 ecb模式    
	std::string des_encrypt(const std::string &clearText, const std::string &key);
	// 解密 ecb模式    
	std::string des_decrypt(const std::string &cipherText, const std::string &key);

	// 函数方法生成密钥对   
	void generateRSAKey(std::string strKey[2]);

	// 命令行方法生成公私钥对(begin public key/ begin private key)  
	// 找到openssl命令行工具,运行如下  
	// openssl genrsa -out prikey.pem 1024   
	// openssl rsa - in privkey.pem - pubout - out pubkey.pem  

	// 公钥加密    
	std::string rsa_pub_encrypt(const std::string &clearText, const std::string &pubKey);
	// 私钥解密    
	std::string rsa_pri_decrypt(const std::string &cipherText, const std::string &priKey);

	//私钥签名
	std::string signMessage(std::string privateKey, std::string plainText);
	//公钥验证
	bool verifySignature(std::string &publicKey, std::string &plainText, std::string &signatureBase64);

 

项目文件:https://gitee.com/feistel/some_openssl加密

相关文章
相关标签/搜索