Last active
March 16, 2023 20:32
-
-
Save joecliff/10948592 to your computer and use it in GitHub Desktop.
cryptojs WordArray usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
Base64.stringify wants a wordArray as the input, not a string. Do that conversion first.
How to get a WordArray from Buffer, this buffer may be created by s.readFileSync(chunkLocalPath)
@gamelife 1314 CryptoJS.enc.Hex.parse()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I've a question about how can I do this following PHP Code
into JS?
It's not work and throw error
crypto-js.js:789 Uncaught TypeError: wordArray.clamp is not a function