本文整理汇总了TypeScript中node-forge.pki类的典型用法代码示例。如果您正苦于以下问题:TypeScript pki类的具体用法?TypeScript pki怎么用?TypeScript pki使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了pki类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: verifySigningChain
verifySigningChain(certChain: string | ICert[] | ICert): boolean {
let forgeCertArray: any[] = [];
if (typeof certChain === "string") {
const rPEM = /\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g;
let forgeCert: any;
let match;
while((match = rPEM.exec(certChain)) !== null) {
try {
forgeCert = forge.pki.certificateFromPem(match[0]);
} catch (error) {
throw new Error(``);
}
forgeCertArray.push(forgeCert);
}
} else if (Array.isArray(certChain)) {
for (let cert of certChain) {
if (isICert(cert)) {
forgeCertArray.push(forge.pki.certificateFromPem(cert.pem));
} else {
throw new Error(``);
}
}
} else if (isICert(certChain)) {
forgeCertArray.push(forge.pki.certificateFromPem(certChain.pem));
} else {
throw new Error(``);
}
return forge.pki.verifyCertificateChain(this._forgeCAStore, forgeCertArray, true);
}
开发者ID:zachmart,项目名称:closedssl,代码行数:32,代码来源:CAStore.ts
示例2: fingerprint
fingerprint(hash: "sha1" | "sha256" | "sha384" | "sha512" | "md5" = "sha1"): string {
let md: any;
const forgeCSR = forge.pki.certificateFromPem(this._pem, true, true);
switch (hash) {
case "sha1":
md = forge.md.sha1.create();
break;
case "sha256":
md = forge.md.sha256.create();
break;
case "sha384":
md = forge.md.sha384.create();
break;
case "sha512":
md = forge.md.sha512.create();
break;
case "md5":
md = forge.md.md5.create();
break;
default:
throw new Error(`Unrecognized message digest hash algorithm: ${hash}`);
}
const result = md
.update(forge.asn1.toDer(forge.pki.certificateToAsn1(forgeCSR)).getBytes())
.digest()
.toHex();
return result;
}
开发者ID:zachmart,项目名称:closedssl,代码行数:31,代码来源:Cert.ts
示例3: 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
示例4: listCertsAsPEMStrings
listCertsAsPEMStrings(): string[] {
const result: string[] = [];
const forgeCerts: any[] = this._forgeCAStore.listAllCertificates();
for (let forgeCert of forgeCerts) {
result.push(forge.pki.certificateToPem(forgeCert));
}
return result;
}
开发者ID:zachmart,项目名称:closedssl,代码行数:10,代码来源:CAStore.ts
示例5: 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
示例6: constructor
constructor(caCerts?: Array<ICert | string>) {
this._forgeCAStore = forge.pki.createCaStore();
if (Array.isArray(caCerts)) {
for (let cert of caCerts) {
this.addCert(cert);
}
} else if (caCerts !== null && typeof caCerts !== "undefined") {
throw new Error(``);
}
}
开发者ID:zachmart,项目名称:closedssl,代码行数:11,代码来源:CAStore.ts
示例7: 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
示例8: 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.');
}
}
开发者ID:ryanseys,项目名称:google-p12-pem,代码行数:18,代码来源:index.ts
示例9: removeCert
removeCert(cert: ICert | string): ICert | null {
let result: null | ICert;
const removedForgeCert = this._forgeCAStore.removeCertificate(
convertICertOrPEMStringToForgeCert(cert)
);
if (removedForgeCert === null) {
result = null;
} else {
result = new Cert(forge.pki.certificateToPem(removedForgeCert));
}
return result;
}
开发者ID:zachmart,项目名称:closedssl,代码行数:15,代码来源:CAStore.ts
示例10: convertICertOrPEMStringToForgeCert
function convertICertOrPEMStringToForgeCert(cert: ICert | string): any {
let certPEM: string;
let forgeCert: any;
if (isICert(cert)) {
certPEM = cert.pem;
} else if (typeof cert === "string") {
certPEM = cert;
} else {
throw new Error(``);
}
try {
forgeCert = forge.pki.certificateFromPem(certPEM);
} catch (error) {
throw new Error(``);
}
return forgeCert;
}
开发者ID:zachmart,项目名称:closedssl,代码行数:20,代码来源:CAStore.ts
注:本文中的node-forge.pki类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论