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("Tests crypto.subtle.encrypt() using a BufferSource that was neutere
d (prior to encrypt())"); |
| 13 |
| 14 jsTestIsAsync = true; |
| 15 |
| 16 data = null; |
| 17 key = null; |
| 18 |
| 19 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); |
| 20 var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f"); |
| 21 var kExpectedCipherTextHex = "c84af0b613435d5d9182801a9bd9320b"; |
| 22 |
| 23 var extractable = true; |
| 24 var usages = ['encrypt', 'decrypt']; |
| 25 |
| 26 debug("Importing key..."); |
| 27 crypto.subtle.importKey('raw', keyData, "aes-cbc", extractable, usages).then(fun
ction(result) { |
| 28 key = result; |
| 29 |
| 30 debug("\nEncrypting empty plaintext (as a control group)..."); |
| 31 return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, new Uint8Array(
)); |
| 32 }).then(function(result) { |
| 33 bytesShouldMatchHexString("Encryption", kExpectedCipherTextHex, result); |
| 34 |
| 35 debug("\nCreating ArrayBuffer..."); |
| 36 plainText = new ArrayBuffer(1000); |
| 37 shouldBe("plainText.byteLength", "1000"); |
| 38 |
| 39 debug("Neutering plainText..."); |
| 40 try { postMessage(plainText, "xxx", [plainText]); } catch (e) { } |
| 41 shouldBe("plainText.byteLength", "0"); |
| 42 |
| 43 debug("\nEncrypting neutered plaintext..."); |
| 44 return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plainText); |
| 45 }).then(function(result) { |
| 46 bytesShouldMatchHexString("Encryption", kExpectedCipherTextHex, result); |
| 47 }).then(finishJSTest, failAndFinishJSTest); |
| 48 </script> |
| 49 |
| 50 </body> |
| 51 </html> |
OLD | NEW |