【发布时间】:2019-12-28 02:40:52
【问题描述】:
如何使用 SHA-256 填充而不是 Crypto++ 中的默认 SHA-1 填充来加密我的字符串数据?我无法找到任何方法来更改我的加密/解密函数使用的填充算法。我听说一些库有硬编码的填充方案,但我希望有一种方法可以修改 Crypto++ 使用的那个。
这是我的加密方法:
string GUIMain::encryptData(const string data) {
CryptoPP::RSAES_OAEP_SHA_Encryptor e(*serverPublic);
string cipher;
CryptoPP::StringSource ss1(data, true, new CryptoPP::PK_EncryptorFilter(*rng, e, new CryptoPP::StringSink(cipher)));
return cipher;
}
这是我的解密方法:
string GUIMain::decryptData(const string cipher) {
CryptoPP::RSAES_OAEP_SHA_Decryptor d(*privateKey);
string recovered;
CryptoPP::StringSource ss2(cipher, true, new CryptoPP::PK_DecryptorFilter(*rng, d, new CryptoPP::StringSink(recovered)));
return recovered;
}
键(*serverPublic 和 *privateKey)分别是对象类型 RSA::PublicKey 和 RSA::PrivateKey。 *rng 是一个 AutoSeededRandomPool 对象。
有什么方法可以添加/更改这些方法以使其正常工作?我是 C++ 新手,所以请尽可能解释解决方案。
【问题讨论】:
-
作为新用户,您可能对Crypto++ wiki 和Crypto++ manual 感兴趣。 wiki 中塞满了示例代码,例如 RSA Cryptography 和 RSA Encryption Schemes。
标签: c++ encryption crypto++