From 1c0ecd29c24b85bf2f37cfb097ddb46f5a95fc69 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 7 Apr 2020 11:45:54 +0100 Subject: [PATCH] Fix RSA operations --- src/core/operations/RSASign.mjs | 10 +++++----- src/core/operations/RSAVerify.mjs | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/operations/RSASign.mjs b/src/core/operations/RSASign.mjs index 812de813..1c2696e3 100644 --- a/src/core/operations/RSASign.mjs +++ b/src/core/operations/RSASign.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation"; import OperationError from "../errors/OperationError"; import forge from "node-forge/dist/forge.min.js"; +import Utils from "../Utils.mjs"; import { MD_ALGORITHMS } from "../lib/RSA.mjs"; /** @@ -26,7 +27,7 @@ class RSASign extends Operation { this.description = "Sign a plaintext message with a PEM encoded RSA key."; this.infoURL = "https://wikipedia.org/wiki/RSA_(cryptosystem)"; this.inputType = "string"; - this.outputType = "byteArray"; + this.outputType = "string"; this.args = [ { name: "RSA Private Key (PEM)", @@ -61,10 +62,9 @@ class RSASign extends Operation { // Generate message hash const md = MD_ALGORITHMS[mdAlgo].create(); md.update(input, "utf8"); - // Convert signature UTF-16 string to byteArray - const encoder = new TextEncoder(); - const signature = encoder.encode(privateKey.sign(md)); - return signature; + // Sign message hash + const sig = privateKey.sign(md); + return sig; } catch (err) { throw new OperationError(err); } diff --git a/src/core/operations/RSAVerify.mjs b/src/core/operations/RSAVerify.mjs index 2041e341..94ca4220 100644 --- a/src/core/operations/RSAVerify.mjs +++ b/src/core/operations/RSAVerify.mjs @@ -6,6 +6,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; +import Utils from "../Utils.mjs"; import forge from "node-forge/dist/forge.min.js"; import { MD_ALGORITHMS } from "../lib/RSA.mjs"; @@ -24,7 +25,7 @@ class RSAVerify extends Operation { this.module = "Ciphers"; this.description = "Verify a message against a signature and a public PEM encoded RSA key."; this.infoURL = "https://wikipedia.org/wiki/RSA_(cryptosystem)"; - this.inputType = "byteArray"; + this.inputType = "string"; this.outputType = "string"; this.args = [ {