OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <script src="../resources/js-test.js"></script> | |
5 <script src="resources/common.js"></script> | |
6 </head> | |
7 <body> | |
8 <p id="description"></p> | |
9 <div id="console"></div> | |
10 | |
11 <script> | |
12 description("Make sure that the usages of an AES key are respected"); | |
13 | |
14 jsTestIsAsync = true; | |
15 | |
16 var data = asciiToUint8Array("hello"); | |
17 var iv = new Uint8Array(16); | |
18 | |
19 function importKeyExcludingUsage(usage) | |
20 { | |
21 var algorithm = {name: 'aes-cbc'}; | |
22 var extractable = false; | |
23 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); | |
24 | |
25 var usages = ["encrypt", "decrypt", "wrapKey", "unwrapKey"]; | |
26 for (var i in usages) { | |
27 if (usages[i] == usage) { | |
28 usages.splice(i, 1); | |
29 break; | |
30 } | |
31 } | |
32 | |
33 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); | |
34 } | |
35 | |
36 function testEncrypt() | |
37 { | |
38 return importKeyExcludingUsage("encrypt").then(function(key) { | |
39 return crypto.subtle.encrypt({name: 'AES-CBC', iv: iv}, key, data); | |
40 }).then(failAndFinishJSTest, function(result) { | |
41 logError(result); | |
42 }); | |
43 } | |
44 | |
45 function testDecrypt() | |
46 { | |
47 return importKeyExcludingUsage("decrypt").then(function(key) { | |
48 return crypto.subtle.decrypt({name: 'AES-CBC', iv: iv}, key, data); | |
49 }).then(failAndFinishJSTest, function(result) { | |
50 logError(result); | |
51 }); | |
52 } | |
53 | |
54 // FIXME: Add wrapKey() and unwrapKey() | |
55 | |
56 testEncrypt().then(testDecrypt).then(finishJSTest, failAndFinishJSTest); | |
57 | |
58 </script> | |
59 | |
60 </body> | |
61 </html> | |
OLD | NEW |