1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-26 01:08:50 -05:00
mail/test/unit/aes-test.js
2013-06-10 22:02:29 +02:00

24 lines
735 B
JavaScript

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