Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created December 13, 2015 03:00
Show Gist options
  • Save lettergram/ba6733a854f835bca22b to your computer and use it in GitHub Desktop.
Save lettergram/ba6733a854f835bca22b to your computer and use it in GitHub Desktop.
CryptoJS.enc.u8array = {
stringify: function (wordArray) {
var words = wordArray.words;
var sigBytes = wordArray.sigBytes;
var u8 = new Uint8Array(sigBytes);
for (var i = 0; i < sigBytes; i++) {
var byte = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
u8[i]=byte;
}
return u8;
},
parse: function (u8arr) {
var len = u8arr.length;
var words = [];
for (var i = 0; i < len; i++) {
words[i >>> 2] |= (u8arr[i] & 0xff) << (24 - (i % 4) * 8);
}
return CryptoJS.lib.WordArray.create(words, len);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment