What is rsa-pem-from-mod-exp?
The rsa-pem-from-mod-exp npm package is used to convert RSA public key components (modulus and exponent) into a PEM formatted string. This is useful for applications that need to handle RSA keys in a standardized format.
What are rsa-pem-from-mod-exp's main functionalities?
Convert RSA modulus and exponent to PEM
This feature allows you to convert RSA public key components (modulus and exponent) into a PEM formatted string. The provided code sample demonstrates how to use the package to achieve this conversion.
const rsaPemFromModExp = require('rsa-pem-from-mod-exp');
const modulus = '00c1b0...'; // Hexadecimal string
const exponent = '010001'; // Hexadecimal string
const pem = rsaPemFromModExp(modulus, exponent);
console.log(pem);
Other packages similar to rsa-pem-from-mod-exp
node-rsa
The node-rsa package provides a comprehensive set of tools for working with RSA keys, including key generation, encryption, decryption, and conversion to/from various formats. It offers more functionality compared to rsa-pem-from-mod-exp, which is focused solely on converting modulus and exponent to PEM format.
pem-jwk
The pem-jwk package allows for conversion between PEM and JWK (JSON Web Key) formats. While it provides broader functionality in terms of key format conversions, it can also handle the specific task of converting RSA modulus and exponent to PEM, similar to rsa-pem-from-mod-exp.
node-forge
The node-forge package is a robust library for implementing various cryptographic functions in JavaScript, including RSA key generation, encryption, decryption, and conversion between different key formats. It offers a wider range of cryptographic utilities compared to rsa-pem-from-mod-exp.
node-rsa-pem-from-mod-exp
Create RSA Public Key PEM from Modulus and Exponent value in node.js. There are no dependencies to other modules for use.
This allows you to use the modulus/exponent values for validating signed value.
The original code is based on the answer to this stackoverflow question.
Install
npm install rsa-pem-from-mod-exp
Usage
var getPem = require('rsa-pem-from-mod-exp');
var modulus = "niqcAxl7LclB0kE6q9AcAd8EE+0W6AsriR9Fs9T+6QVXl8uiCiAbh/KCyy8X8C2bHsFpNBvwGTqMwHbqZqWBVUvYRtfCFcy3Xmertb09DnOBeWqKS4181kss97JDO6G07QNbuLSWwkkO82CHD1kUmeF5/dof0Ra6bsRXqppdo86NzlgFud+E2s5BM3XwewZVSpA69bwEiXaRDhrsg5mqeOm68VyxE8LQu+895kKsBnTvTueZTrXT+HNaIveoYe8+Lb7b/mZYtlhrDK0i/8EDox85vxnzKZ7wNswqqcDg6vfC2911phSTPh13jv2FIOkjO/WHhHEzRnS2VQqivqIbsQ";
var exponent = "AQAB";
var pem = getPem(modulus, exponent);
In the above example pem will now contain the following string.
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAniqcAxl7LclB0kE6q9AcAd8EE+0W6AsriR9Fs9T+6QVXl8uiCiAb
h/KCyy8X8C2bHsFpNBvwGTqMwHbqZqWBVUvYRtfCFcy3Xmertb09DnOBeWqKS418
1kss97JDO6G07QNbuLSWwkkO82CHD1kUmeF5/dof0Ra6bsRXqppdo86NzlgFud+E
2s5BM3XwewZVSpA69bwEiXaRDhrsg5mqeOm68VyxE8LQu+895kKsBnTvTueZTrXT
+HNaIveoYe8+Lb7b/mZYtlhrDK0i/8EDox85vxnzKZ7wNswqqcDg6vfC2911phST
Ph13jv2FIOkjO/WHhHEzRnS2VQqivqIbsQIDAQAB
-----END RSA PUBLIC KEY-----
Testing and Code Coverage
npm test
npm run cover