2013-05-13 11:14:44 -04:00
|
|
|
module("Forge Crypto");
|
|
|
|
|
2013-05-14 10:05:31 -04:00
|
|
|
var forge_rsa_test = {
|
2013-05-13 11:14:44 -04:00
|
|
|
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() {
|
2013-05-22 11:03:54 -04:00
|
|
|
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);
|
2013-05-13 11:14:44 -04:00
|
|
|
});
|