如何使用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.