我正在创建一个ACME https://www.rfc-editor.org/rfc/rfc8555客户端和我需要找到 RSA 公钥的模数和指数,我使用以下代码生成该公钥:
crypto.generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
});
我需要模数和指数,以便我可以在JWK https://www.rfc-editor.org/rfc/rfc7517我的部分JWS https://www.rfc-editor.org/rfc/rfc7515:
alg: 'RS256',
jwk: {
kty: 'RSA',
e: '...',
n: '...'
},
nonce,
url: directory.newAccount
我已经成功地解码了公钥base64 to hex使用以下行,但我不确定下一步该怎么做:
Buffer.from(publicKey, 'base64').toString('hex');
如何在 Node.js 中找到 RSA 公钥的模数和指数?
EDIT 1
我发现 Node.js 默认使用公共指数 65537:Node.js 文档 https://nodejs.org/dist/latest-v14.x/docs/api/crypto.html#crypto_crypto_generatekeypairsync_type_options.