Сниппет генерации с помощью NodeJS
import crypto from 'crypto';
function generateRSA() {
return new Promise((resolve, reject) => {
crypto.generateKeyPair(
'rsa',
{
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
},
},
(error, publicKey, privateKey) => {
if (error) {
return reject(error);
}
resolve({
publicKey,
privateKey,
});
},
);
});
};
Тесты
const { publicKey, privateKey } = await generateRSA();
t.true(publicKey.startsWith('-----BEGIN PUBLIC KEY-----'));
t.true(privateKey.trimEnd().endsWith('-----END PRIVATE KEY-----'));