使用 node-rsa 从 Uint8Array 到 BigInteger 的 RSA 密钥转换

RSA key conversion from Uint8Array to BigInteger with node-rsa

我有一个生成的 RSA 密钥,格式为 Uint8Array,但我需要 BigInteger 格式的密钥。见下图。我怎样才能实现这样的转换?

我使用节点 RSA 库:https://www.npmjs.com/package/node-rsa

我猜测“生成的”密钥是通过调用浏览器提供的 exportKey method, using the ‘components’ format. With this setting, this method returns a fixed-structure object whose values are Buffers holding individual key components; it also appears that you have installed some kind of shim that simulates the node.js Buffer API with the Uint8Array 对象获得的。

如果是这样,那么取回密钥对象所需要做的就是调用 importKey method:

const key = new NodeRSA();
key.importKey(keyData, 'components');