cordis/archive/print-new-key-pair.ts

28 lines
807 B
TypeScript
Raw Normal View History

import * as crypto from 'crypto';
2021-10-30 17:26:41 +00:00
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' }));