cordis/archive/print-new-key-pair.ts
2022-01-25 18:05:01 -06:00

28 lines
807 B
TypeScript

import * as crypto from 'crypto';
const keys = crypto.generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
//cipher: 'aes-256-cbc',
//passphrase: 'top secret'
}
});
console.log(keys.publicKey);
console.log(keys.privateKey);
// const keys2 = crypto.generateKeyPairSync('rsa', {
// modulusLength: 4096
// });
// console.log(keys2.publicKey.export({ type: 'spki', format: 'pem' }));
// console.log(keys2.publicKey.export({ type: 'spki', format: 'der' }));
// console.log(keys2.privateKey.export({ type: 'pkcs8', format: 'pem' }));
// console.log(keys2.privateKey.export({ type: 'pkcs8', format: 'der' }));