TestSuite.add(new YAHOO.tool.TestCase({ | |
test_AES128: function () { | |
// Test vectors | |
Crypto.AES._init([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]); | |
Crypto.AES._encryptblock(block = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], 0); | |
Assert.areEqual("69c4e0d86a7b0430d8cdb78070b4c55a", Crypto.util.bytesToHex(block)); | |
// Test D(E(m)) == m | |
Crypto.AES._encryptblock(block = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], 0); | |
Crypto.AES._decryptblock(block, 0); | |
Assert.areEqual([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF].toString(), block.toString()); | |
var key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"; | |
Assert.areEqual(data, Crypto.AES.decrypt(Crypto.AES.encrypt(data.slice(0), key, { mode: new Crypto.mode.CBC }), key, { mode: new Crypto.mode.CBC, asBytes: true }).toString()); | |
Assert.areEqual(data, Crypto.AES.decrypt(Crypto.AES.encrypt(data.slice(0), key), key, { asBytes: true }).toString()); | |
}, | |
test_AES192: function () { | |
// Test vectors | |
Crypto.AES._init([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17]); | |
Crypto.AES._encryptblock(block = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], 0); | |
Assert.areEqual("dda97ca4864cdfe06eaf70a0ec0d7191", Crypto.util.bytesToHex(block)); | |
// Test D(E(m)) == m | |
Crypto.AES._encryptblock(block = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], 0); | |
Crypto.AES._decryptblock(block, 0); | |
Assert.areEqual([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF].toString(), block.toString()); | |
var key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17"; | |
Assert.areEqual(data, Crypto.AES.decrypt(Crypto.AES.encrypt(data.slice(0), key, { mode: new Crypto.mode.CBC }), key, { mode: new Crypto.mode.CBC, asBytes: true }).toString()); | |
Assert.areEqual(data, Crypto.AES.decrypt(Crypto.AES.encrypt(data.slice(0), key), key, { asBytes: true }).toString()); | |
}, | |
test_AES256: function () { | |
// Test vectors | |
Crypto.AES._init([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]); | |
Crypto.AES._encryptblock(block = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], 0); | |
Assert.areEqual("8ea2b7ca516745bfeafc49904b496089", Crypto.util.bytesToHex(block)); | |
// Test D(E(m)) == m | |
Crypto.AES._encryptblock(block = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], 0); | |
Crypto.AES._decryptblock(block, 0); | |
Assert.areEqual([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF].toString(), block.toString()); | |
var key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; | |
Assert.areEqual(data, Crypto.AES.decrypt(Crypto.AES.encrypt(data.slice(0), key, { mode: new Crypto.mode.CBC }), key, { mode: new Crypto.mode.CBC, asBytes: true }).toString()); | |
Assert.areEqual(data, Crypto.AES.decrypt(Crypto.AES.encrypt(data.slice(0), key), key, { asBytes: true }).toString()); | |
Assert.areEqual('Сообщение', Crypto.AES.decrypt(Crypto.AES.encrypt('Сообщение', 'Пароль'), 'Пароль')); | |
} | |
})); |