From 59f2fc0e737c11379efa8597f4d4e9a8a6b3817d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 18 Jan 2018 00:08:10 -0500 Subject: [PATCH] add b64 output encoding option for decrypt --- src/services/crypto.service.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index adce2e7911..2b378c4202 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -148,8 +148,7 @@ export class CryptoService implements CryptoServiceInterface { return null; } - const privateKey = await this.decrypt(new CipherString(encPrivateKey), null, 'raw'); - const privateKeyB64 = forge.util.encode64(privateKey); + const privateKeyB64 = await this.decrypt(new CipherString(encPrivateKey), null, 'b64'); this.privateKey = UtilsService.fromB64ToArray(privateKeyB64).buffer; return this.privateKey; } @@ -327,8 +326,13 @@ export class CryptoService implements CryptoServiceInterface { if (outputEncoding === 'utf8') { return decipher.output.toString('utf8'); + } + + const decipherBytes = decipher.output.getBytes(); + if (outputEncoding === 'b64') { + return forge.util.encode64(decipherBytes); } else { - return decipher.output.getBytes(); + return decipherBytes; } }