mirror of
https://github.com/gchq/CyberChef
synced 2025-12-17 16:53:45 +00:00
Remove highlighting and correct one module mismatch
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
|
||||||
import { SM2 } from "../lib/SM2.mjs";
|
import { SM2 } from "../lib/SM2.mjs";
|
||||||
@@ -54,6 +55,10 @@ class SM2Decrypt extends Operation {
|
|||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [privateKey, inputFormat, curveName] = args;
|
const [privateKey, inputFormat, curveName] = args;
|
||||||
|
|
||||||
|
if (privateKey.length !== 64) {
|
||||||
|
throw new OperationError("Input private key must be in hex; and should be 32 bytes");
|
||||||
|
}
|
||||||
|
|
||||||
const sm2 = new SM2(curveName, inputFormat);
|
const sm2 = new SM2(curveName, inputFormat);
|
||||||
sm2.setPrivateKey(privateKey);
|
sm2.setPrivateKey(privateKey);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
|
||||||
import { SM2 } from "../lib/SM2.mjs";
|
import { SM2 } from "../lib/SM2.mjs";
|
||||||
@@ -20,7 +21,7 @@ class SM2Encrypt extends Operation {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
this.name = "SM2 Encrypt";
|
this.name = "SM2 Encrypt";
|
||||||
this.module = "Ciphers";
|
this.module = "Crypto";
|
||||||
this.description = "Encrypts a message utilizing the SM2 standard";
|
this.description = "Encrypts a message utilizing the SM2 standard";
|
||||||
this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc)
|
this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc)
|
||||||
this.inputType = "ArrayBuffer";
|
this.inputType = "ArrayBuffer";
|
||||||
@@ -61,33 +62,16 @@ class SM2Encrypt extends Operation {
|
|||||||
const [publicKeyX, publicKeyY, outputFormat, curveName] = args;
|
const [publicKeyX, publicKeyY, outputFormat, curveName] = args;
|
||||||
this.outputFormat = outputFormat;
|
this.outputFormat = outputFormat;
|
||||||
|
|
||||||
|
if (publicKeyX.length !== 64 || publicKeyY.length !== 64) {
|
||||||
|
throw new OperationError("Invalid Public Key - Ensure each component is 32 bytes in size and in hex");
|
||||||
|
}
|
||||||
|
|
||||||
const sm2 = new SM2(curveName, outputFormat);
|
const sm2 = new SM2(curveName, outputFormat);
|
||||||
sm2.setPublicKey(publicKeyX, publicKeyY);
|
sm2.setPublicKey(publicKeyX, publicKeyY);
|
||||||
|
|
||||||
const result = sm2.encrypt(new Uint8Array(input));
|
const result = sm2.encrypt(new Uint8Array(input));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Highlight SM2 Encrypt
|
|
||||||
*
|
|
||||||
* @param {Object[]} pos
|
|
||||||
* @param {number} pos[].start
|
|
||||||
* @param {number} pos[].end
|
|
||||||
* @param {Object[]} args
|
|
||||||
* @returns {Object[]} pos
|
|
||||||
*/
|
|
||||||
highlight(pos, args) {
|
|
||||||
const outputFormat = args[2];
|
|
||||||
const num = pos[0].end - pos[0].start;
|
|
||||||
let adjust = 128;
|
|
||||||
if (outputFormat === "C1C3C2") {
|
|
||||||
adjust = 192;
|
|
||||||
}
|
|
||||||
pos[0].start = Math.ceil(pos[0].start + adjust);
|
|
||||||
pos[0].end = Math.floor(pos[0].end + adjust + num);
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SM2Encrypt;
|
export default SM2Encrypt;
|
||||||
|
|||||||
Reference in New Issue
Block a user