繁体   English   中英

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

[英]How to use Crypto++ and return printable byte/char array for RSA?

我正在使用以下 function 使用 RSA 加密包含不可打印字节的字节数组。 然而,这个 function 返回一个字符串值并丢失不可打印的字节。

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;
}

我怎样才能返回字节数组呢?

文档中:

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

主页上也列出了各种其他编码器,从底部开始第二行。 Base64Encoder最有意义。

当然解密需要再次解码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM