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

Method convertToByteString

src/core/Utils.mjs:379–395  ·  view source on GitHub ↗

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

(str, type)

Source from the content-addressed store, hash-verified

377 * Utils.convertToByteString("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64");
378 */
379 static convertToByteString(str, type) {
380 switch (type.toLowerCase()) {
381 case "binary":
382 return Utils.byteArrayToChars(fromBinary(str));
383 case "hex":
384 return Utils.byteArrayToChars(fromHex(str));
385 case "decimal":
386 return Utils.byteArrayToChars(fromDecimal(str));
387 case "base64":
388 return Utils.byteArrayToChars(fromBase64(str, null, "byteArray"));
389 case "utf8":
390 return utf8.encode(str);
391 case "latin1":
392 default:
393 return str;
394 }
395 }
396
397
398 /**

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
byteArrayToCharsMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected