MCPcopy
hub / github.com/gchq/CyberChef / convertToByteArray

Method convertToByteArray

src/core/Utils.mjs:342–358  ·  view source on GitHub ↗

* Coverts data of varying types to a byteArray. * Accepts hex, Base64, UTF8 and Latin1 strings. * * @param {string} str * @param {string} type - One of "Binary", "Hex", "Decimal", "Base64", "UTF8" or "Latin1" * @returns {byteArray} * * @example * // returns [2

(str, type)

Source from the content-addressed store, hash-verified

340 * Utils.convertToByteArray("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64");
341 */
342 static convertToByteArray(str, type) {
343 switch (type.toLowerCase()) {
344 case "binary":
345 return fromBinary(str);
346 case "hex":
347 return fromHex(str);
348 case "decimal":
349 return fromDecimal(str);
350 case "base64":
351 return fromBase64(str, null, "byteArray");
352 case "utf8":
353 return Utils.strToUtf8ByteArray(str);
354 case "latin1":
355 default:
356 return Utils.strToByteArray(str);
357 }
358 }
359
360
361 /**

Callers 15

runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80

Calls 6

fromBinaryFunction · 0.90
fromHexFunction · 0.90
fromDecimalFunction · 0.90
fromBase64Function · 0.90
strToUtf8ByteArrayMethod · 0.80
strToByteArrayMethod · 0.80

Tested by

no test coverage detected