mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-01 05:31:01 +01:00
Added message format arg to RSA Verify operation
This commit is contained in:
parent
d3adfc7c3e
commit
47c85a105d
@ -8,6 +8,7 @@ import Operation from "../Operation.mjs";
|
|||||||
import OperationError from "../errors/OperationError.mjs";
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import forge from "node-forge";
|
import forge from "node-forge";
|
||||||
import { MD_ALGORITHMS } from "../lib/RSA.mjs";
|
import { MD_ALGORITHMS } from "../lib/RSA.mjs";
|
||||||
|
import Utils from "../Utils.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RSA Verify operation
|
* RSA Verify operation
|
||||||
@ -37,6 +38,11 @@ class RSAVerify extends Operation {
|
|||||||
type: "text",
|
type: "text",
|
||||||
value: ""
|
value: ""
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Message format",
|
||||||
|
type: "option",
|
||||||
|
value: ["Raw", "Hex", "Base64"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Message Digest Algorithm",
|
name: "Message Digest Algorithm",
|
||||||
type: "option",
|
type: "option",
|
||||||
@ -51,7 +57,7 @@ class RSAVerify extends Operation {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [pemKey, message, mdAlgo] = args;
|
const [pemKey, message, format, mdAlgo] = args;
|
||||||
if (pemKey.replace("-----BEGIN RSA PUBLIC KEY-----", "").length === 0) {
|
if (pemKey.replace("-----BEGIN RSA PUBLIC KEY-----", "").length === 0) {
|
||||||
throw new OperationError("Please enter a public key.");
|
throw new OperationError("Please enter a public key.");
|
||||||
}
|
}
|
||||||
@ -60,7 +66,8 @@ class RSAVerify extends Operation {
|
|||||||
const pubKey = forge.pki.publicKeyFromPem(pemKey);
|
const pubKey = forge.pki.publicKeyFromPem(pemKey);
|
||||||
// Generate message digest
|
// Generate message digest
|
||||||
const md = MD_ALGORITHMS[mdAlgo].create();
|
const md = MD_ALGORITHMS[mdAlgo].create();
|
||||||
md.update(message, "raw");
|
const messageStr = Utils.convertToByteString(message, format);
|
||||||
|
md.update(messageStr, "raw");
|
||||||
// Compare signed message digest and generated message digest
|
// Compare signed message digest and generated message digest
|
||||||
const result = pubKey.verify(md.digest().bytes(), input);
|
const result = pubKey.verify(md.digest().bytes(), input);
|
||||||
return result ? "Verified OK" : "Verification Failure";
|
return result ? "Verified OK" : "Verification Failure";
|
||||||
|
Loading…
Reference in New Issue
Block a user