如何使用Crypto ++并为RSA返回可打印的字节/字符数组?

问题描述 投票:-1回答:1

我正在使用以下功能通过RSA加密我的消息。但是,此函数返回一个字符串值,并且包含不可打印的字节。

string RSAencrypt(RSA::PublicKey publicKey,string plain) {
    string cipher;

    try {
        AutoSeededRandomPool rng;
        RSAES_OAEP_SHA_Encryptor e(publicKey);

        StringSource ss1(plain, true,
            new PK_EncryptorFilter(rng, e,
                new StringSink(cipher)
            ) // PK_EncryptorFilter
        ); // StringSource

    }
    catch (CryptoPP::Exception & e)
    {
        cerr << "Caught Exception..." << endl;
        cerr << e.what() << endl;
    }
    return cipher;
}

如何生成可打印字节?

c++ cryptography rsa crypto++
1个回答
0
投票

documentation

new HexEncoder(
    new StringSink(encoded)
) // HexEncoder

main page的第二行,还有从底部第二行列出的其他各种编码器。 Base64Encoder最有意义。

© www.soinside.com 2019 - 2024. All rights reserved.