diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs index af96beaf..18823daf 100755 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -5,6 +5,7 @@ */ import Utils from "./Utils"; +import {fromHex} from "./lib/Hex"; /** * The arguments to operations. @@ -88,7 +89,7 @@ class Ingredient { case "byteArray": if (typeof data == "string") { data = data.replace(/\s+/g, ""); - return Utils.fromHex(data); + return fromHex(data); } else { return data; } diff --git a/src/core/Utils.mjs b/src/core/Utils.mjs index 0ee29e0d..2be207eb 100755 --- a/src/core/Utils.mjs +++ b/src/core/Utils.mjs @@ -7,6 +7,7 @@ import utf8 from "utf8"; import moment from "moment-timezone"; import {fromBase64} from "./lib/Base64"; +import {toHexFast, fromHex} from "./lib/Hex"; /** @@ -312,7 +313,7 @@ class Utils { static convertToByteArray(str, type) { switch (type.toLowerCase()) { case "hex": - return Utils.fromHex(str); + return fromHex(str); case "base64": return fromBase64(str, null, "byteArray"); case "utf8": @@ -345,7 +346,7 @@ class Utils { static convertToByteString(str, type) { switch (type.toLowerCase()) { case "hex": - return Utils.byteArrayToChars(Utils.fromHex(str)); + return Utils.byteArrayToChars(fromHex(str)); case "base64": return Utils.byteArrayToChars(fromBase64(str, null, "byteArray")); case "utf8": @@ -519,95 +520,6 @@ class Utils { } - /** - * Convert a byte array into a hex string. - * - * @param {Uint8Array|byteArray} data - * @param {string} [delim=" "] - * @param {number} [padding=2] - * @returns {string} - * - * @example - * // returns "0a 14 1e" - * Utils.toHex([10,20,30]); - * - * // returns "0a:14:1e" - * Utils.toHex([10,20,30], ":"); - */ - static toHex(data, delim=" ", padding=2) { - if (!data) return ""; - - let output = ""; - - for (let i = 0; i < data.length; i++) { - output += data[i].toString(16).padStart(padding, "0") + delim; - } - - // Add \x or 0x to beginning - if (delim === "0x") output = "0x" + output; - if (delim === "\\x") output = "\\x" + output; - - if (delim.length) - return output.slice(0, -delim.length); - else - return output; - } - - - /** - * Convert a byte array into a hex string as efficiently as possible with no options. - * - * @param {byteArray} data - * @returns {string} - * - * @example - * // returns "0a141e" - * Utils.toHex([10,20,30]); - */ - static toHexFast(data) { - if (!data) return ""; - - const output = []; - - for (let i = 0; i < data.length; i++) { - output.push((data[i] >>> 4).toString(16)); - output.push((data[i] & 0x0f).toString(16)); - } - - return output.join(""); - } - - - /** - * Convert a hex string into a byte array. - * - * @param {string} data - * @param {string} [delim] - * @param {number} [byteLen=2] - * @returns {byteArray} - * - * @example - * // returns [10,20,30] - * Utils.fromHex("0a 14 1e"); - * - * // returns [10,20,30] - * Utils.fromHex("0a:14:1e", "Colon"); - */ - static fromHex(data, delim, byteLen=2) { - delim = delim || (data.indexOf(" ") >= 0 ? "Space" : "None"); - if (delim !== "None") { - const delimRegex = Utils.regexRep(delim); - data = data.replace(delimRegex, ""); - } - - const output = []; - for (let i = 0; i < data.length; i += byteLen) { - output.push(parseInt(data.substr(i, byteLen), 16)); - } - return output; - } - - /** * Parses CSV data and returns it as a two dimensional array or strings. * @@ -944,7 +856,7 @@ class Utils { title='Download ${Utils.escapeHtml(file.fileName)}' download='${Utils.escapeHtml(file.fileName)}'>💾`; - const hexFileData = Utils.toHexFast(new Uint8Array(file.bytes)); + const hexFileData = toHexFast(new Uint8Array(file.bytes)); const switchToInputElem = `
e.g. ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a becomes the UTF-8 encoded string Γειά σου", + "inputType": "string", + "outputType": "byteArray", + "flowControl": false, + "args": [ + { + "name": "Delimiter", + "type": "option", + "value": [ + "Space", + "Comma", + "Semi-colon", + "Colon", + "Line feed", + "CRLF", + "0x", + "\\x", + "None" + ] + } + ] + }, "Show Base64 offsets": { "module": "Default", "description": "When a string is within a block of data and the whole block is Base64'd, the string itself could be represented in Base64 in three distinct ways depending on its offset within the block.

This operation shows all possible offsets for a given string so that each possible encoding can be considered.", @@ -189,5 +213,29 @@ ] } ] + }, + "To Hex": { + "module": "Default", + "description": "Converts the input string to hexadecimal bytes separated by the specified delimiter.

e.g. The UTF-8 encoded string Γειά σου becomes ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a", + "inputType": "ArrayBuffer", + "outputType": "string", + "flowControl": false, + "args": [ + { + "name": "Delimiter", + "type": "option", + "value": [ + "Space", + "Comma", + "Semi-colon", + "Colon", + "Line feed", + "CRLF", + "0x", + "\\x", + "None" + ] + } + ] } } \ No newline at end of file diff --git a/src/core/config/modules/Default.mjs b/src/core/config/modules/Default.mjs index d5ac0684..46b35030 100644 --- a/src/core/config/modules/Default.mjs +++ b/src/core/config/modules/Default.mjs @@ -7,18 +7,22 @@ */ import FromBase32 from "../../operations/FromBase32"; import FromBase64 from "../../operations/FromBase64"; +import FromHex from "../../operations/FromHex"; import ShowBase64Offsets from "../../operations/ShowBase64Offsets"; import ToBase32 from "../../operations/ToBase32"; import ToBase64 from "../../operations/ToBase64"; +import ToHex from "../../operations/ToHex"; const OpModules = typeof self === "undefined" ? {} : self.OpModules || {}; OpModules.Default = { "From Base32": FromBase32, "From Base64": FromBase64, + "From Hex": FromHex, "Show Base64 offsets": ShowBase64Offsets, "To Base32": ToBase32, "To Base64": ToBase64, + "To Hex": ToHex, }; export default OpModules; diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs new file mode 100644 index 00000000..242d434a --- /dev/null +++ b/src/core/lib/Hex.mjs @@ -0,0 +1,104 @@ +/** + * Byte representation functions. + * + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2016 + * @license Apache-2.0 + */ + +import Utils from "../Utils"; + + +/** + * Convert a byte array into a hex string. + * + * @param {Uint8Array|byteArray} data + * @param {string} [delim=" "] + * @param {number} [padding=2] + * @returns {string} + * + * @example + * // returns "0a 14 1e" + * toHex([10,20,30]); + * + * // returns "0a:14:1e" + * toHex([10,20,30], ":"); + */ +export function toHex(data, delim=" ", padding=2) { + if (!data) return ""; + + let output = ""; + + for (let i = 0; i < data.length; i++) { + output += data[i].toString(16).padStart(padding, "0") + delim; + } + + // Add \x or 0x to beginning + if (delim === "0x") output = "0x" + output; + if (delim === "\\x") output = "\\x" + output; + + if (delim.length) + return output.slice(0, -delim.length); + else + return output; +} + + +/** + * Convert a byte array into a hex string as efficiently as possible with no options. + * + * @param {byteArray} data + * @returns {string} + * + * @example + * // returns "0a141e" + * toHex([10,20,30]); + */ +export function toHexFast(data) { + if (!data) return ""; + + const output = []; + + for (let i = 0; i < data.length; i++) { + output.push((data[i] >>> 4).toString(16)); + output.push((data[i] & 0x0f).toString(16)); + } + + return output.join(""); +} + + +/** + * Convert a hex string into a byte array. + * + * @param {string} data + * @param {string} [delim] + * @param {number} [byteLen=2] + * @returns {byteArray} + * + * @example + * // returns [10,20,30] + * fromHex("0a 14 1e"); + * + * // returns [10,20,30] + * fromHex("0a:14:1e", "Colon"); + */ +export function fromHex(data, delim, byteLen=2) { + delim = delim || (data.indexOf(" ") >= 0 ? "Space" : "None"); + if (delim !== "None") { + const delimRegex = Utils.regexRep(delim); + data = data.replace(delimRegex, ""); + } + + const output = []; + for (let i = 0; i < data.length; i += byteLen) { + output.push(parseInt(data.substr(i, byteLen), 16)); + } + return output; +} + + +/** + * Hexadecimal delimiters. + */ +export const HEX_DELIM_OPTIONS = ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "\\x", "None"]; diff --git a/src/core/operations/FromHex.mjs b/src/core/operations/FromHex.mjs new file mode 100644 index 00000000..17557196 --- /dev/null +++ b/src/core/operations/FromHex.mjs @@ -0,0 +1,98 @@ +/** + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2016 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import {fromHex, HEX_DELIM_OPTIONS} from "../lib/Hex"; +import Utils from "../Utils"; + +/** + * From Hex operation + */ +class FromHex extends Operation { + + /** + * FromHex constructor + */ + constructor() { + super(); + + this.name = "From Hex"; + this.module = "Default"; + this.description = "Converts a hexadecimal byte string back into its raw value.

e.g. ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a becomes the UTF-8 encoded string Γειά σου"; + this.inputType = "string"; + this.outputType = "byteArray"; + this.args = [ + { + name: "Delimiter", + type: "option", + value: HEX_DELIM_OPTIONS + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {byteArray} + */ + run(input, args) { + const delim = args[0] || "Space"; + return fromHex(input, delim, 2); + } + + /** + * Highlight to Hex + * + * @param {Object[]} pos + * @param {number} pos[].start + * @param {number} pos[].end + * @param {Object[]} args + * @returns {Object[]} pos + */ + highlight(pos, args) { + const delim = Utils.charRep(args[0] || "Space"), + len = delim === "\r\n" ? 1 : delim.length, + width = len + 2; + + // 0x and \x are added to the beginning if they are selected, so increment the positions accordingly + if (delim === "0x" || delim === "\\x") { + if (pos[0].start > 1) pos[0].start -= 2; + else pos[0].start = 0; + if (pos[0].end > 1) pos[0].end -= 2; + else pos[0].end = 0; + } + + pos[0].start = pos[0].start === 0 ? 0 : Math.round(pos[0].start / width); + pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / width); + return pos; + } + + /** + * Highlight from Hex + * + * @param {Object[]} pos + * @param {number} pos[].start + * @param {number} pos[].end + * @param {Object[]} args + * @returns {Object[]} pos + */ + highlightReverse(pos, args) { + const delim = Utils.charRep(args[0] || "Space"), + len = delim === "\r\n" ? 1 : delim.length; + + pos[0].start = pos[0].start * (2 + len); + pos[0].end = pos[0].end * (2 + len) - len; + + // 0x and \x are added to the beginning if they are selected, so increment the positions accordingly + if (delim === "0x" || delim === "\\x") { + pos[0].start += 2; + pos[0].end += 2; + } + return pos; + } +} + +export default FromHex; diff --git a/src/core/operations/ToHex.mjs b/src/core/operations/ToHex.mjs new file mode 100644 index 00000000..d9b89b11 --- /dev/null +++ b/src/core/operations/ToHex.mjs @@ -0,0 +1,98 @@ +/** + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2016 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import {toHex, HEX_DELIM_OPTIONS} from "../lib/Hex"; +import Utils from "../Utils"; + +/** + * To Hex operation + */ +class ToHex extends Operation { + + /** + * ToHex constructor + */ + constructor() { + super(); + + this.name = "To Hex"; + this.module = "Default"; + this.description = "Converts the input string to hexadecimal bytes separated by the specified delimiter.

e.g. The UTF-8 encoded string Γειά σου becomes ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a"; + this.inputType = "ArrayBuffer"; + this.outputType = "string"; + this.args = [ + { + name: "Delimiter", + type: "option", + value: HEX_DELIM_OPTIONS + } + ]; + } + + /** + * @param {ArrayBuffer} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const delim = Utils.charRep(args[0] || "Space"); + return toHex(new Uint8Array(input), delim, 2); + } + + /** + * Highlight to Hex + * + * @param {Object[]} pos + * @param {number} pos[].start + * @param {number} pos[].end + * @param {Object[]} args + * @returns {Object[]} pos + */ + highlight(pos, args) { + const delim = Utils.charRep(args[0] || "Space"), + len = delim === "\r\n" ? 1 : delim.length; + + pos[0].start = pos[0].start * (2 + len); + pos[0].end = pos[0].end * (2 + len) - len; + + // 0x and \x are added to the beginning if they are selected, so increment the positions accordingly + if (delim === "0x" || delim === "\\x") { + pos[0].start += 2; + pos[0].end += 2; + } + return pos; + } + + /** + * Highlight from Hex + * + * @param {Object[]} pos + * @param {number} pos[].start + * @param {number} pos[].end + * @param {Object[]} args + * @returns {Object[]} pos + */ + highlightReverse(pos, args) { + const delim = Utils.charRep(args[0] || "Space"), + len = delim === "\r\n" ? 1 : delim.length, + width = len + 2; + + // 0x and \x are added to the beginning if they are selected, so increment the positions accordingly + if (delim === "0x" || delim === "\\x") { + if (pos[0].start > 1) pos[0].start -= 2; + else pos[0].start = 0; + if (pos[0].end > 1) pos[0].end -= 2; + else pos[0].end = 0; + } + + pos[0].start = pos[0].start === 0 ? 0 : Math.round(pos[0].start / width); + pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / width); + return pos; + } +} + +export default ToHex; diff --git a/src/core/operations/index.mjs b/src/core/operations/index.mjs index 3f3675ed..45ba1e22 100644 --- a/src/core/operations/index.mjs +++ b/src/core/operations/index.mjs @@ -3,11 +3,15 @@ import FromBase64 from "./FromBase64"; import ToBase32 from "./ToBase32"; import FromBase32 from "./FromBase32"; import ShowBase64Offsets from "./ShowBase64Offsets"; +import ToHex from "./ToHex"; +import FromHex from "./FromHex"; export { ToBase64, FromBase64, ToBase32, FromBase32, - ShowBase64Offsets + ShowBase64Offsets, + ToHex, + FromHex }; diff --git a/src/core/operations/legacy/BitwiseOp.js b/src/core/operations/legacy/BitwiseOp.js index f2551cba..26408096 100755 --- a/src/core/operations/legacy/BitwiseOp.js +++ b/src/core/operations/legacy/BitwiseOp.js @@ -1,4 +1,5 @@ import Utils from "../Utils.js"; +import {toHex} from "../lib/Hex"; /** @@ -166,7 +167,7 @@ const BitwiseOp = { if (crib && resultUtf8.toLowerCase().indexOf(crib) < 0) continue; if (printKey) record += "Key = " + Utils.hex(key, (2*keyLength)) + ": "; if (outputHex) { - record += Utils.toHex(result); + record += toHex(result); } else { record += Utils.printable(resultUtf8, false); } diff --git a/src/core/operations/legacy/ByteRepr.js b/src/core/operations/legacy/ByteRepr.js index bc2287a1..6bf91bb6 100755 --- a/src/core/operations/legacy/ByteRepr.js +++ b/src/core/operations/legacy/ByteRepr.js @@ -1,4 +1,5 @@ import Utils from "../Utils.js"; +import {toHex, fromHex} from "../lib/Hex"; /** @@ -17,42 +18,12 @@ const ByteRepr = { * @default */ DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF"], - /** - * @constant - * @default - */ - HEX_DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "\\x", "None"], /** * @constant * @default */ BIN_DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "None"], - /** - * To Hex operation. - * - * @param {ArrayBuffer} input - * @param {Object[]} args - * @returns {string} - */ - runToHex: function(input, args) { - const delim = Utils.charRep(args[0] || "Space"); - return Utils.toHex(new Uint8Array(input), delim, 2); - }, - - - /** - * From Hex operation. - * - * @param {string} input - * @param {Object[]} args - * @returns {byteArray} - */ - runFromHex: function(input, args) { - const delim = args[0] || "Space"; - return Utils.fromHex(input, delim, 2); - }, - /** * To Octal operation. @@ -171,59 +142,6 @@ const ByteRepr = { }, - /** - * Highlight to hex - * - * @param {Object[]} pos - * @param {number} pos[].start - * @param {number} pos[].end - * @param {Object[]} args - * @returns {Object[]} pos - */ - highlightTo: function(pos, args) { - let delim = Utils.charRep(args[0] || "Space"), - len = delim === "\r\n" ? 1 : delim.length; - - pos[0].start = pos[0].start * (2 + len); - pos[0].end = pos[0].end * (2 + len) - len; - - // 0x and \x are added to the beginning if they are selected, so increment the positions accordingly - if (delim === "0x" || delim === "\\x") { - pos[0].start += 2; - pos[0].end += 2; - } - return pos; - }, - - - /** - * Highlight from hex - * - * @param {Object[]} pos - * @param {number} pos[].start - * @param {number} pos[].end - * @param {Object[]} args - * @returns {Object[]} pos - */ - highlightFrom: function(pos, args) { - let delim = Utils.charRep(args[0] || "Space"), - len = delim === "\r\n" ? 1 : delim.length, - width = len + 2; - - // 0x and \x are added to the beginning if they are selected, so increment the positions accordingly - if (delim === "0x" || delim === "\\x") { - if (pos[0].start > 1) pos[0].start -= 2; - else pos[0].start = 0; - if (pos[0].end > 1) pos[0].end -= 2; - else pos[0].end = 0; - } - - pos[0].start = pos[0].start === 0 ? 0 : Math.round(pos[0].start / width); - pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / width); - return pos; - }, - - /** * To Decimal operation. * @@ -357,7 +275,7 @@ const ByteRepr = { const convert = args[0]; const spaces = args[1]; if (convert === "All chars") { - let result = "|" + Utils.toHex(input) + "|"; + let result = "|" + toHex(input) + "|"; if (!spaces) result = result.replace(/ /g, ""); return result; } @@ -373,7 +291,7 @@ const ByteRepr = { output += "|"; inHex = true; } else if (spaces) output += " "; - output += Utils.toHex([b]); + output += toHex([b]); } else { if (inHex) { output += "|"; @@ -403,7 +321,7 @@ const ByteRepr = { output.push(Utils.ord(input[i++])); // Add match - const bytes = Utils.fromHex(m[1]); + const bytes = fromHex(m[1]); if (bytes) { for (let a = 0; a < bytes.length;) output.push(bytes[a++]); diff --git a/src/core/operations/legacy/Cipher.js b/src/core/operations/legacy/Cipher.js index b343f218..e350c17a 100755 --- a/src/core/operations/legacy/Cipher.js +++ b/src/core/operations/legacy/Cipher.js @@ -1,5 +1,6 @@ import Utils from "../Utils.js"; import {toBase64} from "../lib/Base64"; +import {toHexFast} from "../lib/Hex"; import CryptoJS from "crypto-js"; import forge from "imports-loader?jQuery=>null!node-forge/dist/forge.min.js"; import {blowfish as Blowfish} from "sladex-blowfish"; @@ -403,7 +404,7 @@ DES uses a key length of 8 bytes (64 bits).`; cipherMode: Cipher._BLOWFISH_MODE_LOOKUP[mode] }); - return outputType === "Hex" ? Utils.toHexFast(Utils.strToByteArray(result)) : result; + return outputType === "Hex" ? toHexFast(Utils.strToByteArray(result)) : result; }, diff --git a/src/core/operations/legacy/Endian.js b/src/core/operations/legacy/Endian.js index bb0f9136..a2ec7703 100755 --- a/src/core/operations/legacy/Endian.js +++ b/src/core/operations/legacy/Endian.js @@ -1,4 +1,5 @@ import Utils from "../Utils.js"; +import {toHex, fromHex} from "../lib/Hex"; /** @@ -52,7 +53,7 @@ const Endian = { // Convert input to raw data based on specified data format switch (dataFormat) { case "Hex": - data = Utils.fromHex(input); + data = fromHex(input); break; case "Raw": data = Utils.strToByteArray(input); @@ -86,7 +87,7 @@ const Endian = { // Convert data back to specified data format switch (dataFormat) { case "Hex": - return Utils.toHex(result); + return toHex(result); case "Raw": return Utils.byteArrayToUtf8(result); default: diff --git a/src/core/operations/legacy/Hexdump.js b/src/core/operations/legacy/Hexdump.js index a10a7060..2626217a 100755 --- a/src/core/operations/legacy/Hexdump.js +++ b/src/core/operations/legacy/Hexdump.js @@ -1,4 +1,5 @@ import Utils from "../Utils.js"; +import {fromHex} from "../lib/Hex"; /** @@ -82,7 +83,7 @@ const Hexdump = { block, line; while ((block = regex.exec(input))) { - line = Utils.fromHex(block[1].replace(/-/g, " ")); + line = fromHex(block[1].replace(/-/g, " ")); for (let i = 0; i < line.length; i++) { output.push(line[i]); } diff --git a/src/core/operations/legacy/IP.js b/src/core/operations/legacy/IP.js index 13481e12..c4c3c18f 100755 --- a/src/core/operations/legacy/IP.js +++ b/src/core/operations/legacy/IP.js @@ -1,4 +1,5 @@ import Utils from "../Utils.js"; +import {toHex, fromHex} from "../lib/Hex"; import Checksum from "./Checksum.js"; import {BigInteger} from "jsbn"; @@ -283,7 +284,7 @@ const IP = { baIp.push(decimal & 255); break; case "Hex": - baIp = Utils.fromHex(lines[i]); + baIp = fromHex(lines[i]); break; default: throw "Unsupported input IP format"; @@ -445,7 +446,7 @@ const IP = { output; if (format === "Hex") { - input = Utils.fromHex(input); + input = fromHex(input); } else if (format === "Raw") { input = Utils.strToByteArray(input); } else { @@ -516,7 +517,7 @@ const IP = { "Destination IP address" + IP._ipv4ToStr(dstIP) + ""; if (ihl > 5) { - output += "Options" + Utils.toHex(options) + ""; + output += "Options" + toHex(options) + ""; } return output + ""; diff --git a/src/core/operations/legacy/Image.js b/src/core/operations/legacy/Image.js index cf3c568f..23581382 100644 --- a/src/core/operations/legacy/Image.js +++ b/src/core/operations/legacy/Image.js @@ -3,6 +3,7 @@ import removeEXIF from "../vendor/remove-exif.js"; import Utils from "../Utils.js"; import FileType from "./FileType.js"; import {fromBase64, toBase64} from "../lib/Base64"; +import {fromHex} from "../lib/Hex"; /** @@ -92,7 +93,7 @@ const Image = { // Convert input to raw bytes switch (inputFormat) { case "Hex": - input = Utils.fromHex(input); + input = fromHex(input); break; case "Base64": // Don't trust the Base64 entered by the user. diff --git a/src/core/operations/legacy/PublicKey.js b/src/core/operations/legacy/PublicKey.js index c0512705..80c35196 100755 --- a/src/core/operations/legacy/PublicKey.js +++ b/src/core/operations/legacy/PublicKey.js @@ -1,5 +1,6 @@ import Utils from "../Utils.js"; import {fromBase64} from "../lib/Base64"; +import {toHex, fromHex} from "../lib/Hex"; import * as r from "jsrsasign"; @@ -44,10 +45,10 @@ const PublicKey = { cert.readCertPEM(input); break; case "Base64": - cert.readCertHex(Utils.toHex(fromBase64(input, null, "byteArray"), "")); + cert.readCertHex(toHex(fromBase64(input, null, "byteArray"), "")); break; case "Raw": - cert.readCertHex(Utils.toHex(Utils.strToByteArray(input), "")); + cert.readCertHex(toHex(Utils.strToByteArray(input), "")); break; default: throw "Undefined input format"; @@ -305,7 +306,7 @@ ${extensions}`; * @returns {string} */ _formatByteStr: function(byteStr, length, indent) { - byteStr = Utils.toHex(Utils.fromHex(byteStr), ":"); + byteStr = toHex(fromHex(byteStr), ":"); length = length * 3; let output = ""; diff --git a/src/core/operations/legacy/StrUtils.js b/src/core/operations/legacy/StrUtils.js index c43252e7..9a5c010e 100755 --- a/src/core/operations/legacy/StrUtils.js +++ b/src/core/operations/legacy/StrUtils.js @@ -1,4 +1,5 @@ import Utils from "../Utils.js"; +import {fromHex} from "../lib/Hex"; import jsesc from "jsesc"; @@ -380,8 +381,8 @@ const StrUtils = { } if (inputType === "Hex") { - samples[0] = Utils.fromHex(samples[0]); - samples[1] = Utils.fromHex(samples[1]); + samples[0] = fromHex(samples[0]); + samples[1] = fromHex(samples[1]); } else { samples[0] = Utils.strToByteArray(samples[0]); samples[1] = Utils.strToByteArray(samples[1]);