python - 将 CryptoPP RSA 唱歌函数转换为 Python
问题描述
我有一个用 C++ 和 CrypoPP 编写的签名/验证桌面应用程序。我需要将签名函数转换为 Python,以便它可以用作 Web 服务。
void signMessage(const std::string & privateKeyStrHex, const std::vector<char> & vec, std::string & sign)
{
// Pseudo Random Number Generator
CryptoPP::AutoSeededRandomPool rng;
// Generate Parameters
CryptoPP::InvertibleRSAFunction params;
params.GenerateRandomWithKeySize( rng, 1536 );
CryptoPP::HexDecoder decoder;
decoder.Put( (byte*)privateKeyStrHex.c_str(), privateKeyStrHex.size() );
decoder.MessageEnd();
CryptoPP::RSA::PrivateKey privateKey; // Private
privateKey.Load( decoder );
CryptoPP::RSASS<CryptoPP::PSS, CryptoPP::SHA1>::Signer signer( privateKey );
size_t length = signer.MaxSignatureLength();
CryptoPP::SecByteBlock signature( length );
// Sign message
signer.SignMessage( rng, (const byte*) utils::GetBeginOf(vec),
vec.size(), signature );
sign = utils::wstring2string(utils::ToHexString<byte>(signature, signature.size()));
}
我面临的主要问题是使用 RASASS PSS 算法并指定盐长度。
https://pycryptodome.readthedocs.io/en/latest/src/signature/pkcs1_pss.html
这是我所指的文档,但没有太多细节。
谢谢!
解决方案
推荐阅读
- azure-ad-b2c - 为什么 b2c_1_edit_profile 的弹出窗口消失了?
- flutter - 无法弄清楚如何将代码放入 kotlin 并使用方法通道从颤振中发送函数
- visual-studio-code - LogDebug 到 VS Studio Code 中的调试控制台
- image - Facebook 主页个人资料图片上传不起作用。如何上传页面图片?
- java - 在 docker 容器中运行的 Java(JDK8 更新 131 之前)应用程序 CPU/内存问题?
- python - 为什么对空列表/字典的断言失败?
- python - 如何获得单词/短语的语义
- flutter - 如何在 Flutter 中为容器的底部边框设置动画?
- javascript - Vue3 观察者 - 观察者何时按生命周期事件的顺序运行?
- microsoft-graph-api - 使用 Graph API 的带有多个附件的电子邮件 (>4 MB)