openssl封装的RSA加解密方法
openssl使用rsa加解密,C++封装,支持设置公钥、私钥,公钥加解密,私钥加解密。
使用方法很简单:
CRSAEncoder mRSAEncoderPC; //设置公钥 mRSAEncoderPC.SetPublicKey("-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQE..........XApYoMnPE3g4xU4NceOBTFZtR5fp+w/MswIDAQAB\n-----END PUBLIC KEY-----"); //公钥解密 std::string strTest = mRSAEncoderPC.PublicDecrypt("......"); //公钥加密 strTest = mRSAEncoderPC.PublicEncrypt("......"); //另外一种 unsigned char d[] = { 0x38, 0x60, 0x63, 0x56, 0xBC, 0x54, 0x52, 0xBC, 0xA6, 0xB6, 0xDB, 0x47, 0x49, 0x08, 0xE5, 0xB8, 0x0B, 0xAA, 0x44, 0xEC, 0x49, 0x2B, 0x35, 0x5F, 0xBB, 0x1A, 0xB2, 0x29, 0x2D, 0x0F, 0x2D, 0xE2, 0x93, 0x70, 0x4D, 0x8F, 0x6F, 0x01, 0x64, 0xE4, 0xC9, 0x0C, 0x03, 0x4C, 0x02, 0x08, 0xE6, 0xB7, 0xAF, 0xBB, 0x8A, 0x0A, 0xFF, 0x84, 0xB4, 0xBA, 0x9E, 0x4B, 0x1A, 0xB2, 0x0A, 0x75, 0xDA, 0xFD, 0x0E, 0xBE, 0x73, 0xCA, 0x5C, 0xFC, 0xA2, 0x4D, 0xCF, 0x56, 0xA8, 0xAD, 0x9D, 0xC3, 0x60, 0x86, 0xF5, 0xA8, 0xA0, 0xD0, 0xCD, 0x7E, 0x21, 0x8A, 0xCE, 0x4C, 0xCD, 0x03, 0xDE, 0x76, 0xF6, 0xA5, 0x95, 0xA9, 0x77, 0x77, 0xFF, 0xF9, 0xBA, 0x3B, 0x0F, 0xD9, 0xFF, 0x50, 0x63, 0x6E, 0xDD, 0x49, 0xFA, 0x31, 0x7D, 0xE0, 0xC5, 0x81, 0xC5, 0x75, 0x79, 0xCE, 0x1C, 0x78, 0x1A, 0x94, 0xD6, 0x7A, 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 0xFC, 0x45, 0x34, 0x04, 0x6D, 0xD1, 0x6E, 0xF7, 0x2D, 0x96, 0xB3, 0xD3, 0xAE, 0x43, 0xC3, 0x4D, 0x26, 0x23, 0x5E, 0x7F }; unsigned char e[] = { 0x01, 0x00, 0x01 }; CRSAEncoder mRSAEncoder; //设置私钥 mRSAEncoder.SetPrivateKey(n, sizeof(n), e, sizeof(e), d, sizeof(d)); //设置私钥另外一个姿势也可以的 //mRSAEncoder.SetPrivateKey("-----BEGIN PRIVATE KEY-----\nMIICeAIBA..............DANBQltd+11\n-----END PRIVATE KEY-----"); //私钥加密 FString strEnBuf = mRSAEncoder.PrivateEncrypt("......"); //私钥解密 strEnBuf = mRSAEncoder.PrivateDecrypt("......");
blackfeather 2024/11/19 ℃ 0评论