ltijs
Version:
Easily turn your web application into a LTI 1.3 Learning Tool.
28 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateKeyPair = generateKeyPair;
exports.jwkToRsa = jwkToRsa;
exports.rsaToJwk = rsaToJwk;
const node_crypto_1 = require("node:crypto");
const node_util_1 = require("node:util");
const RSA_MODULUS_LENGTH = 2048;
const PUBLIC_KEY_ENCODING = { type: 'spki', format: 'pem' };
const PRIVATE_KEY_ENCODING = { type: 'pkcs1', format: 'pem' };
// Promisified callback-based generateKeyPair, not the synchronous generateKeyPairSync -- offloads
// RSA-2048 generation (tens of ms of CPU) to libuv's threadpool instead of blocking the event loop.
const generateKeyPairAsync = (0, node_util_1.promisify)(node_crypto_1.generateKeyPair);
async function generateKeyPair() {
const { publicKey, privateKey } = await generateKeyPairAsync('rsa', {
modulusLength: RSA_MODULUS_LENGTH,
publicKeyEncoding: PUBLIC_KEY_ENCODING,
privateKeyEncoding: PRIVATE_KEY_ENCODING,
});
return { public: publicKey, private: privateKey };
}
function jwkToRsa(jwk) {
return (0, node_crypto_1.createPublicKey)({ key: jwk, format: 'jwk' });
}
function rsaToJwk(pem) {
return (0, node_crypto_1.createPublicKey)(pem).export({ format: 'jwk' });
}
//# sourceMappingURL=keys.js.map