Skip to content

Instantly share code, notes, and snippets.

@joecliff
Last active March 16, 2023 20:32
Show Gist options
  • Save joecliff/10948592 to your computer and use it in GitHub Desktop.
Save joecliff/10948592 to your computer and use it in GitHub Desktop.
cryptojs WordArray usage
/**
* cryptojs use WordArray (CryptoJS.lib.WordArray) as parameter/result frequently.
* A WordArray object represents an array of 32-bit words. When you pass a string,
* it's automatically converted to a WordArray encoded as UTF-8.
*/
var CryptoJS = require("crypto-js");
// convert String to WordArray
var wordArray = CryptoJS.enc.Utf8.parse('Hello, World!');
// convert WordArray To String
var result1=wordArray.toString(CryptoJS.enc.Utf8);
var result2=CryptoJS.enc.Utf8.stringify(wordArray);
console.log(result1);
console.log(result1===result2);
@RobinSmithTHR
Copy link

Base64.stringify wants a wordArray as the input, not a string. Do that conversion first.

@gamelife1314
Copy link

How to get a WordArray from Buffer, this buffer may be created by s.readFileSync(chunkLocalPath)

@rankun203
Copy link

@gamelife 1314 CryptoJS.enc.Hex.parse()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment