首页 > 解决方案 > 将 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

这是我所指的文档,但没有太多细节。

谢谢!

标签: pythonpython-3.xcryptographyrsacrypto++

解决方案


推荐阅读