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

24 lines
735 B
JavaScript
Raw Normal View History

2013-06-10 11:57:33 -04:00
define(['cryptoLib/aes-cbc', 'cryptoLib/util', 'test/test-data'], function(aes, util, testData) {
'use strict';
2013-03-13 11:58:46 -04:00
2013-06-10 11:57:33 -04:00
module("AES Crypto");
2013-03-13 11:58:46 -04:00
2013-06-10 16:02:29 -04:00
var aesTest = {
2013-06-10 11:57:33 -04:00
keySize: 128,
2013-06-10 16:02:29 -04:00
testMessage: testData.generateBigString(1000)
2013-06-10 11:57:33 -04:00
};
2013-03-13 11:58:46 -04:00
2013-06-10 11:57:33 -04:00
test("CBC mode", 4, function() {
2013-06-10 16:02:29 -04:00
var plaintext = aesTest.testMessage;
var key = util.random(aesTest.keySize);
var iv = util.random(aesTest.keySize);
2013-06-10 11:57:33 -04:00
ok(key, 'Key: ' + key);
2013-06-10 16:02:29 -04:00
equal(util.base642Str(key).length * 8, aesTest.keySize, 'Keysize ' + aesTest.keySize);
2013-03-13 11:58:46 -04:00
2013-06-10 11:57:33 -04:00
var ciphertext = aes.encrypt(plaintext, key, iv);
ok(ciphertext, 'Ciphertext lenght: ' + ciphertext.length);
2013-03-13 11:58:46 -04:00
2013-06-10 11:57:33 -04:00
var decrypted = aes.decrypt(ciphertext, key, iv);
equal(decrypted, plaintext, 'Decryption correct' + decrypted);
});
});