1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-23 07:48:48 -05:00
mail/test/unit/aes-test.js

23 lines
724 B
JavaScript
Raw Normal View History

2013-03-13 11:58:46 -04:00
module("AES Crypto");
var aes_test = {
2013-05-14 10:05:31 -04:00
keySize: 128,
util: new cryptoLib.Util(window, uuid),
2013-05-14 10:05:31 -04:00
test_message: new TestData().generateBigString(1000)
2013-03-13 11:58:46 -04:00
};
test("CBC mode", 4, function() {
var aes = new cryptoLib.AesCBC(forge);
2013-03-13 11:58:46 -04:00
var plaintext = aes_test.test_message;
var key = aes_test.util.random(aes_test.keySize);
var iv = aes_test.util.random(aes_test.keySize);
ok(key, 'Key: ' + key);
2013-05-14 06:57:09 -04:00
equal(aes_test.util.base642Str(key).length * 8, aes_test.keySize, 'Keysize ' + aes_test.keySize);
2013-03-13 11:58:46 -04:00
var ciphertext = aes.encrypt(plaintext, key, iv);
ok(ciphertext, 'Ciphertext lenght: ' + ciphertext.length);
2013-03-13 11:58:46 -04:00
var decrypted = aes.decrypt(ciphertext, key, iv);
2013-03-13 11:58:46 -04:00
equal(decrypted, plaintext, 'Decryption correct' + decrypted);
});