crypto.createPrivateKey is a function that accepts one argument and returns a new key (object(KeyObject)) that contains a private key.
crypto.createPrivateKey(key)
The
crypto.createPrivatekeyfunction was added in node version 11.6.0, earlier versions of node don’t support this function.
stringArrayBufferBufferTypedArrayDataViewObjectpem and the format must be a string.der; otherwise, it is ignored. The type must be a string.string or Buffer.const crypto = require("crypto");//generate encrypted privateKeyconst {publicKey, privateKey } = crypto.generateKeyPairSync('rsa',{modulusLength: 4096,publicKeyEncoding: {type: 'spki',format: 'pem'},privateKeyEncoding: {type: 'pkcs8',format: 'pem',cipher: 'aes-256-cbc',passphrase: ''}});//generate key Objectconst keyObject = crypto.createPrivateKey({key: privateKey,format: "pem",type: "pkcs1",passphrase: "",encoding: "utf-8"});export default keyObject;
Free Resources