1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-15 05:35:05 -05:00
mail/test/unit/forge-test.js

40 lines
1005 B
JavaScript
Raw Normal View History

module("Forge Crypto");
2013-05-14 10:05:31 -04:00
var forge_rsa_test = {
keySize: 1024,
test_message: '06a9214036b8a15b512e03d534120006'
};
2013-05-13 20:07:28 -04:00
var forge_aes_test = {
keySize: 128,
test_message: new TestData().generateBigString(1000)
};
2013-05-14 07:19:56 -04:00
test("SHA-1 Hash", 1, function() {
var sha1 = forge.md.sha1.create();
sha1.update(forge_aes_test.test_message);
2013-05-14 10:05:31 -04:00
var digest = sha1.digest().toHex();
ok(digest, digest);
2013-05-14 07:19:56 -04:00
});
test("SHA-256 Hash", 1, function() {
2013-05-14 10:05:31 -04:00
forge_rsa_test.md = forge.md.sha256.create();
forge_rsa_test.md.update(forge_aes_test.test_message);
var digest = forge_rsa_test.md.digest().toHex();
ok(digest, digest);
2013-05-14 07:19:56 -04:00
});
test("HMAC SHA-256", 1, function() {
var util = new cryptoLib.Util(window, uuid);
2013-05-14 07:19:56 -04:00
var key = util.base642Str(util.random(forge_aes_test.keySize));
var iv = util.base642Str(util.random(forge_aes_test.keySize));
var hmac = forge.hmac.create();
hmac.start('sha256', key);
hmac.update(iv);
hmac.update(forge_aes_test.test_message);
2013-05-14 10:05:31 -04:00
var digest = hmac.digest().toHex();
2013-05-14 07:19:56 -04:00
2013-05-14 10:05:31 -04:00
ok(digest, digest);
});