diff --git a/build/webcrypto.js b/build/webcrypto.js index d25335e0..b373315d 100644 --- a/build/webcrypto.js +++ b/build/webcrypto.js @@ -32,7 +32,7 @@ return CryptoJS.HmacSHA256( CryptoJS.enc.Latin1.parse(getString(input)), CryptoJS.enc.Latin1.parse(getString(key)) - ).toString(CryptoJS.enc.Latin1); + ); }; function encryptAESCBC(plaintext, key, iv) { @@ -43,7 +43,7 @@ CryptoJS.enc.Latin1.parse(getString(plaintext)), CryptoJS.enc.Latin1.parse(getString(key)), { iv: CryptoJS.enc.Latin1.parse(getString(iv)) } - ).ciphertext.toString(CryptoJS.enc.Latin1); + ).ciphertext; }; function decryptAESCBC(ciphertext, key, iv) { @@ -54,7 +54,7 @@ btoa(getString(ciphertext)), CryptoJS.enc.Latin1.parse(getString(key)), { iv: CryptoJS.enc.Latin1.parse(getString(iv)) } - ).toString(CryptoJS.enc.Latin1); + ); }; // utility function for connecting front and back ends via promises @@ -63,7 +63,14 @@ var args = Array.prototype.slice.call(arguments); args.shift(); return new Promise(function(resolve) { - resolve(toArrayBuffer(implementation.apply(this, args))); + var wordArray = implementation.apply(this, args); + // convert 32bit WordArray to array buffer + var buffer = new ArrayBuffer(wordArray.sigBytes); + var view = new DataView(buffer); + for(var i = 0; i*4 < buffer.byteLength; i++) { + view.setInt32(i*4, wordArray.words[i]); + } + resolve(buffer); }); }; diff --git a/js/helpers.js b/js/helpers.js index c4df1f45..18e36971 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -117,8 +117,7 @@ function getStringable(thing) { (thing === Object(thing) && (thing.__proto__ == StaticArrayBufferProto || thing.__proto__ == StaticUint8ArrayProto || - thing.__proto__ == StaticByteBufferProto || - thing.__proto__ == StaticWordArrayProto))); + thing.__proto__ == StaticByteBufferProto))); } function isEqual(a, b, mayBeShort) { diff --git a/js/webcrypto.js b/js/webcrypto.js index 024d40c8..8fe21303 100644 --- a/js/webcrypto.js +++ b/js/webcrypto.js @@ -2578,7 +2578,7 @@ CryptoJS.lib.Cipher || (function (undefined) { return CryptoJS.HmacSHA256( CryptoJS.enc.Latin1.parse(getString(input)), CryptoJS.enc.Latin1.parse(getString(key)) - ).toString(CryptoJS.enc.Latin1); + ); }; function encryptAESCBC(plaintext, key, iv) { @@ -2589,7 +2589,7 @@ CryptoJS.lib.Cipher || (function (undefined) { CryptoJS.enc.Latin1.parse(getString(plaintext)), CryptoJS.enc.Latin1.parse(getString(key)), { iv: CryptoJS.enc.Latin1.parse(getString(iv)) } - ).ciphertext.toString(CryptoJS.enc.Latin1); + ).ciphertext; }; function decryptAESCBC(ciphertext, key, iv) { @@ -2600,7 +2600,7 @@ CryptoJS.lib.Cipher || (function (undefined) { btoa(getString(ciphertext)), CryptoJS.enc.Latin1.parse(getString(key)), { iv: CryptoJS.enc.Latin1.parse(getString(iv)) } - ).toString(CryptoJS.enc.Latin1); + ); }; // utility function for connecting front and back ends via promises @@ -2609,7 +2609,14 @@ CryptoJS.lib.Cipher || (function (undefined) { var args = Array.prototype.slice.call(arguments); args.shift(); return new Promise(function(resolve) { - resolve(toArrayBuffer(implementation.apply(this, args))); + var wordArray = implementation.apply(this, args); + // convert 32bit WordArray to array buffer + var buffer = new ArrayBuffer(wordArray.sigBytes); + var view = new DataView(buffer); + for(var i = 0; i*4 < buffer.byteLength; i++) { + view.setInt32(i*4, wordArray.words[i]); + } + resolve(buffer); }); };