diff --git a/js/crypto.js b/js/crypto.js index 0e3b3967..a90e9465 100644 --- a/js/crypto.js +++ b/js/crypto.js @@ -764,13 +764,13 @@ window.textsecure.crypto = function() { return window.textsecure.subtle.encrypt({name: "AES-CBC", iv: iv}, aes_key, plaintext).then(function(ciphertext) { var ivAndCiphertext = new Uint8Array(16 + ciphertext.byteLength); - ivAndCiphertext.set(iv); - ivAndCiphertext.set(ciphertext, 16); + ivAndCiphertext.set(new Uint8Array(iv)); + ivAndCiphertext.set(new Uint8Array(ciphertext), 16); return HmacSHA256(mac_key, ivAndCiphertext.buffer).then(function(mac) { var encryptedBin = new Uint8Array(16 + ciphertext.byteLength + 32); - encryptedBin.set(ivAndCiphertext.buffer); - encryptedBin.set(mac, 16 + ciphertext.byteLength); + encryptedBin.set(ivAndCiphertext); + encryptedBin.set(new Uint8Array(mac), 16 + ciphertext.byteLength); return encryptedBin.buffer; }); }); diff --git a/js/helpers.js b/js/helpers.js index 131e6d25..106c861b 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -594,7 +594,7 @@ window.textsecure.subscribeToPush = function(message_callback) { var handleAttachment = function(attachment) { return textsecure.api.getAttachment(attachment.id.toString()).then(function(encryptedBin) { - return textsecure.crypto.decryptAttachment(encryptedBin, toArrayBuffer(attachment.key)).then(function(decryptedBin) { + return textsecure.crypto.decryptAttachment(encryptedBin, attachment.key.toArrayBuffer()).then(function(decryptedBin) { attachment.decrypted = decryptedBin; }); });