小编Pat*_*ell的帖子

为什么65537不使用CryptoPP将base64URL编码为"AQAB"?

我正在使用CryptoPP生成RSA密钥对,以允许对游戏服务器进行身份验证.我需要base64URL编码我的公共指数和模数以包含在JWK中但是我遇到了一些问题.代码显示了我如何生成RSA密钥,提取指数并对其进行编码:

typedef InvertibleRSAFunction RSAPrivateKey;
typedef RSAFunction RSAPublicKey;

RSAPrivateKey privateKey;
privateKey.Initialize( rng, 1024);

RSAPublicKey publicKey( privateKey );

const Integer& e = privateKey.GetPublicExponent();

Base64Encoder exponentSink(new StringSink(exponentString));
e.DEREncode(exponentSink);
exponentSink.MessageEnd();
base64URL(exponentString);

cout << "exponentString: " << exponentString << endl;
Run Code Online (Sandbox Code Playgroud)

base64URL函数只过滤=,+,\n和/字符的字符串,使其成为base64URL.

我知道CryptoPP使用的指数为17,上面的代码将其编码为"AgER".我从众多来源中读到65537编码为"AQAB",我通过手动设置e来尝试将其作为测试.当我这样做时,输出是"AgMBAAE",而不是"AQAB".

当我使用https://www.base64encode.org/等在线转换器时,输出是"NjU1Mzc".

有人可以解释所有这些差异来自何处以及17的正确编码是什么?谢谢!

c++ base64 encoding rsa crypto++

4
推荐指数
1
解决办法
1860
查看次数

标签 统计

base64 ×1

c++ ×1

crypto++ ×1

encoding ×1

rsa ×1