當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript pki.publicKeyToPem方法代碼示例

本文整理匯總了TypeScript中node-forge.pki.publicKeyToPem方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript pki.publicKeyToPem方法的具體用法?TypeScript pki.publicKeyToPem怎麽用?TypeScript pki.publicKeyToPem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在node-forge.pki的用法示例。


在下文中一共展示了pki.publicKeyToPem方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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),
  }
}
開發者ID:ahmb84,項目名稱:prisma,代碼行數:10,代碼來源:crypto.ts

示例2: constructor

  constructor(arg: string | ICSR) {
    if (isICSR(arg)) {
      this._publicKeyPEM = arg.publicKeyPEM;
      this._numBits = arg.numBits;
      this._pem = arg.pem;
      this._subject = arg.subject;
      this._v3Extensions = arg.v3Extensions;
      this._hash = arg.hash;
      this._challengePassword = arg.challengePassword;
      this._unstructuredName = arg.unstructuredName;
    } else if (typeof arg === "string") {
      let forgeCSR: any;

      try {
        forgeCSR = forge.pki.certificationRequestFromPem(arg, true, true);
      } catch (error) {
        throw new Error(`Could not construct CSR from given pem string "${arg}"${"\n"
        }issue: ${error.message}`);
      }
      this._publicKeyPEM = forge.pki.publicKeyToPem(forgeCSR.publicKey);
      this._numBits = forgeCSR.publicKey.n.bitLength();
      this._pem = arg;
      this._subject = DistinguishedName.forgeCSROrCertToIDN(forgeCSR, "subject");
      this._v3Extensions = forgeCSROrCertToV3ExtensionArray(forgeCSR);
      this._hash = forgeCSR.md.algorithm;

      if (forgeCSR.getAttribute({name: "challengePassword"})) {
        this._challengePassword
          = forgeCSR.getAttribute({name: "challengePassword"}).value;
      } else {
        this._challengePassword = null;
      }

      if (forgeCSR.getAttribute({name: "unstructuredName"})) {
        this._unstructuredName = forgeCSR.getAttribute({name: "unstructuredName"}).value;
      } else {
        this._unstructuredName = null;
      }

    } else {
      throw new Error(`The CSR constructor argument "${arg}" is not acceptable`);
    }
  }
開發者ID:zachmart,項目名稱:closedssl,代碼行數:43,代碼來源:CSR.ts

示例3: constructor

  constructor(arg: string | ICert) {
    if (isICert(arg)) {
      this._publicKeyPEM = arg.publicKeyPEM;
      this._numBits = arg.numBits;
      this._pem = arg.pem;
      this._subject = arg.subject;
      this._issuer = arg.issuer;
      this._v3Extensions = arg.v3Extensions;
      this._serial = arg.serial;
      this._hash = arg.hash;
      this._startDate = (typeof arg.startDate === "number") ?
        new Date(arg.startDate)
        :
        arg.startDate;
      this._endDate = (typeof arg.endDate === "number") ?
        new Date(arg.endDate)
        :
        arg.endDate;
    } else if (typeof arg === "string") {
      let forgeCert: any;

      try {
        forgeCert = forge.pki.certificateFromPem(arg, true, true);
      } catch (error) {
        throw new Error(`Could not construct Cert from given pem string "${arg}"${"\n"
          }issue: ${error.message}`);
      }
      this._publicKeyPEM = forge.pki.publicKeyToPem(forgeCert.publicKey);
      this._numBits = forgeCert.publicKey.n.bitLength();
      this._pem = arg;
      this._subject = DistinguishedName.forgeCSROrCertToIDN(forgeCert, "subject");
      this._issuer = DistinguishedName.forgeCSROrCertToIDN(forgeCert, "issuer");
      this._v3Extensions = forgeCSROrCertToV3ExtensionArray(forgeCert);
      this._serial = parseInt(forgeCert.serialNumber, 16);
      this._hash = forgeCert.md.algorithm;
      this._startDate = forgeCert.validity.notBefore;
      this._endDate = forgeCert.validity.notAfter;
    } else {
      throw new Error(`The Cert constructor argument "${arg}" is not acceptable`);
    }
  }
開發者ID:zachmart,項目名稱:closedssl,代碼行數:41,代碼來源:Cert.ts

示例4:

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, [])
            ])
        ])
    ]);
開發者ID:j-f1,項目名稱:forked-DefinitelyTyped,代碼行數:31,代碼來源:node-forge-tests.ts


注:本文中的node-forge.pki.publicKeyToPem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。