jiewen_tan@apple.com | 83b6301 | 2016-11-18 21:31:42 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <script src="../../resources/js-test-pre.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("Test encrypting using AES-CBC with an imported 128bit key"); |
| 13 | |
| 14 | jsTestIsAsync = true; |
| 15 | |
| 16 | var extractable = false; |
| 17 | var plainText = asciiToUint8Array("Hello, World!"); |
| 18 | var aesCbcParams = { |
| 19 | name: "aes-cbc", |
| 20 | iv: asciiToUint8Array("jnOw99oOZFLIEPMr"), |
| 21 | } |
| 22 | var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr"); |
| 23 | var expectedCipherText = "2ffa4618784dfd414b22c40c6330d022"; |
| 24 | |
| 25 | crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["encrypt"]).then(function(key) { |
| 26 | return crypto.subtle.encrypt(aesCbcParams, key, plainText); |
| 27 | }).then(function(result) { |
| 28 | cipherText = result; |
| 29 | |
| 30 | shouldBe("bytesToHexString(cipherText)", "expectedCipherText"); |
| 31 | |
| 32 | finishJSTest(); |
| 33 | }); |
| 34 | |
| 35 | </script> |
| 36 | |
| 37 | <script src="../../resources/js-test-post.js"></script> |
| 38 | </body> |
| 39 | </html> |