| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| <script src="../resources/common.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| |
| <script> |
| description("Test encrypting using AES-GCM with an imported 128bit key and tagLengths"); |
| |
| jsTestIsAsync = true; |
| |
| var extractable = false; |
| var plainText = asciiToUint8Array("Hello, World!"); |
| var iv = asciiToUint8Array("jnOw99oOZFLIEPMr") |
| var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr"); |
| var expectedCipherText32 = "f9ba1161a16c9fcc726a4531c1b520925e"; |
| var expectedCipherText64 = "f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b"; |
| var expectedCipherText96 = "f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f3"; |
| var expectedCipherText104 = "f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f34e"; |
| var expectedCipherText112 = "f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f34e1f"; |
| var expectedCipherText120 = "f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f34e1f3b"; |
| var expectedCipherText128 = "f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f34e1f3ba1"; |
| |
| crypto.subtle.importKey("raw", rawKey, "aes-gcm", extractable, ["encrypt"]).then(function(result) { |
| key = result; |
| |
| return crypto.subtle.encrypt({ name: "aes-gcm", iv: iv, tagLength: 32 }, key, plainText); |
| }).then(function(result) { |
| cipherText = result; |
| shouldBe("bytesToHexString(cipherText)", "expectedCipherText32"); |
| |
| return crypto.subtle.encrypt({ name: "aes-gcm", iv: iv, tagLength: 64 }, key, plainText); |
| }).then(function(result) { |
| cipherText = result; |
| shouldBe("bytesToHexString(cipherText)", "expectedCipherText64"); |
| |
| return crypto.subtle.encrypt({ name: "aes-gcm", iv: iv, tagLength: 96 }, key, plainText); |
| }).then(function(result) { |
| cipherText = result; |
| shouldBe("bytesToHexString(cipherText)", "expectedCipherText96"); |
| |
| return crypto.subtle.encrypt({ name: "aes-gcm", iv: iv, tagLength: 104 }, key, plainText); |
| }).then(function(result) { |
| cipherText = result; |
| shouldBe("bytesToHexString(cipherText)", "expectedCipherText104"); |
| |
| return crypto.subtle.encrypt({ name: "aes-gcm", iv: iv, tagLength: 112 }, key, plainText); |
| }).then(function(result) { |
| cipherText = result; |
| shouldBe("bytesToHexString(cipherText)", "expectedCipherText112"); |
| |
| return crypto.subtle.encrypt({ name: "aes-gcm", iv: iv, tagLength: 120 }, key, plainText); |
| }).then(function(result) { |
| cipherText = result; |
| shouldBe("bytesToHexString(cipherText)", "expectedCipherText120"); |
| |
| return crypto.subtle.encrypt({ name: "aes-gcm", iv: iv, tagLength: 128 }, key, plainText); |
| }).then(function(result) { |
| cipherText = result; |
| shouldBe("bytesToHexString(cipherText)", "expectedCipherText128"); |
| |
| finishJSTest(); |
| }); |
| |
| </script> |
| |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |