基於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加密

相關文章
相關標籤/搜索