【发布时间】:2020-08-13 09:58:09
【问题描述】:
我正在创建一个ACME 客户端,我需要找到我使用以下代码生成的 RSA 公钥的模数和指数:
crypto.generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
});
我需要模数和指数,以便可以在我的JWS 的JWK 部分中使用它们:
alg: 'RS256',
jwk: {
kty: 'RSA',
e: '...',
n: '...'
},
nonce,
url: directory.newAccount
我已设法使用以下行将公钥从 base64 解码为 hex,但我不确定下一步该怎么做:
Buffer.from(publicKey, 'base64').toString('hex');
如何在 Node.js 中找到 RSA 公钥的模数和指数?
编辑 1
我发现 Node.js 默认使用公共指数 65537:Node.js documentation。
【问题讨论】:
-
pem-jwk 是可能的。
标签: javascript node.js rsa public-key