From 269b59210cba1114ff75519c9d0b391406f94bd3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 2 Jul 2018 23:57:22 -0400 Subject: [PATCH] use rsaExtractPublicKey for getting public key --- src/services/crypto.service.ts | 2 +- src/services/nodeCryptoFunction.service.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index 8c913ad8cc..356d15ccae 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -146,7 +146,7 @@ export class CryptoService implements CryptoServiceAbstraction { return null; } - this.publicKey = null; // TODO: + this.publicKey = await this.cryptoFunctionService.rsaExtractPublicKey(privateKey); return this.publicKey; } diff --git a/src/services/nodeCryptoFunction.service.ts b/src/services/nodeCryptoFunction.service.ts index ee154c06e6..7af5de0ffb 100644 --- a/src/services/nodeCryptoFunction.service.ts +++ b/src/services/nodeCryptoFunction.service.ts @@ -133,14 +133,15 @@ export class NodeCryptoFunctionService implements CryptoFunctionService { return Promise.resolve(this.toArrayBuffer(decipher)); } - async rsaExtractPublicKey(privateKey: ArrayBuffer): Promise { + rsaExtractPublicKey(privateKey: ArrayBuffer): Promise { const privateKeyByteString = Utils.fromBufferToByteString(privateKey); const privateKeyAsn1 = forge.asn1.fromDer(privateKeyByteString); const forgePrivateKey = (forge as any).pki.privateKeyFromAsn1(privateKeyAsn1); const forgePublicKey = (forge.pki as any).setRsaPublicKey(forgePrivateKey.n, forgePrivateKey.e); const publicKeyAsn1 = (forge.pki as any).publicKeyToAsn1(forgePublicKey); const publicKeyByteString = forge.asn1.toDer(publicKeyAsn1).data; - return Utils.fromByteStringToArray(publicKeyByteString).buffer; + const publicKeyArray = Utils.fromByteStringToArray(publicKeyByteString); + return Promise.resolve(publicKeyArray.buffer); } randomBytes(length: number): Promise {