diff --git a/js/webcrypto.js b/js/webcrypto.js index 50fc40a8..71d3ce23 100644 --- a/js/webcrypto.js +++ b/js/webcrypto.js @@ -58,6 +58,15 @@ window.textsecure.subtle = (function() { .toString(CryptoJS.enc.Latin1); }; + function encryptAESCBC(plaintext, key, iv) { + assertIsArrayBuffer(plaintext); + assertIsArrayBuffer(key); + assertIsArrayBuffer(iv); + return CryptoJS.AES.encrypt(btoa(getString(plaintext)), + CryptoJS.enc.Latin1.parse(getString(key)), + {iv: CryptoJS.enc.Latin1.parse(getString(iv))}) + .toString(CryptoJS.enc.Latin1); + }; function decryptAESCBC(ciphertext, key, iv) { assertIsArrayBuffer(ciphertext); assertIsArrayBuffer(key); @@ -80,6 +89,8 @@ window.textsecure.subtle = (function() { function encrypt(algorithm, key, data) { if (algorithm.name === "AES-CTR") return promise(encryptAESCTR, data, key, algorithm.counter); + if (algorithm.name === "AES-CBC") + return promise(encryptAESCBC, data, key, algorithm.iv); }; function decrypt(algorithm, key, data) { if (algorithm.name === "AES-CTR")