本文整理汇总了TypeScript中node-forge.pki.privateKeyToPem方法的典型用法代码示例。如果您正苦于以下问题:TypeScript pki.privateKeyToPem方法的具体用法?TypeScript pki.privateKeyToPem怎么用?TypeScript pki.privateKeyToPem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node-forge.pki
的用法示例。
在下文中一共展示了pki.privateKeyToPem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createRsaKeyPair
export async function createRsaKeyPair(): Promise<KeyPair> {
const keypair = await promisify(forge.pki.rsa.generateKeyPair)({
bits: 2048,
})
return {
public: forge.pki.publicKeyToPem(keypair.publicKey),
private: forge.pki.privateKeyToPem(keypair.privateKey),
}
}
示例2: convertToPem
/**
* Converts a P12 in base64 encoding to a pem.
* @param p12base64 String containing base64 encoded p12.
* @returns a string containing the pem.
*/
function convertToPem(p12base64: string): string {
const p12Der = forge.util.decode64(p12base64);
const p12Asn1 = forge.asn1.fromDer(p12Der);
const p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, 'notasecret');
const bags = p12.getBags({friendlyName: 'privatekey'});
if (bags.friendlyName) {
const privateKey = bags.friendlyName[0].key!;
const pem = forge.pki.privateKeyToPem(privateKey);
return pem.replace(/\r\n/g, '\n');
} else {
throw new Error('Unable to get friendly name.');
}
}
示例3:
import * as forge from 'node-forge';
let keypair = forge.pki.rsa.generateKeyPair({ bits: 512 });
let privateKeyPem = forge.pki.privateKeyToPem(keypair.privateKey);
let publicKeyPem = forge.pki.publicKeyToPem(keypair.publicKey);
let key = forge.pki.decryptRsaPrivateKey(privateKeyPem);
let x: string = forge.ssh.privateKeyToOpenSSH(key);
let pemKey: forge.pki.PEM = publicKeyPem;
let publicKeyRsa = forge.pki.publicKeyFromPem(pemKey);
let privateKeyRsa = forge.pki.privateKeyFromPem(privateKeyPem);
let byteBufferString = forge.pki.pemToDer(privateKeyPem);
let cert = forge.pki.createCertificate();
{
let subjectPublicKeyInfo = forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.SEQUENCE, true, [
forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.SEQUENCE, true, [
forge.asn1.create(
forge.asn1.Class.UNIVERSAL,
forge.asn1.Type.OID,
false,
forge.asn1.oidToDer(forge.pki.oids['rsaEncryption']).getBytes()
),
forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.NULL, false, '')
]),
forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.BITSTRING, false, [
forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.SEQUENCE, true, [
forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.INTEGER, false, []),
forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.INTEGER, false, [])
])
])
]);