【问题标题】:How to use Crypto++ and return printable byte/char array for RSA?如何使用 Crypto++ 并为 RSA 返回可打印的字节/字符数组?
【发布时间】:2020-02-24 13:52:16
【问题描述】:

我正在使用以下函数来加密包含使用 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】:

来自documentation

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

main page(倒数第二行)还列出了其他各种编码器。 Base64Encoder 最有意义。

当然你需要解码再次之前解密。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-21
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 2013-11-17
    相关资源
    最近更新 更多