Add support for cbc encryption

This commit is contained in:
lilia 2014-10-24 19:09:58 -07:00
parent 229007040c
commit 674b173c59

View file

@ -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")