| <!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 decrypting using AES-GCM with an imported 128bit key and tagLengths"); |
| |
| jsTestIsAsync = true; |
| |
| var extractable = false; |
| var expectedPlainText = "Hello, World!"; |
| var iv = asciiToUint8Array("jnOw99oOZFLIEPMr") |
| var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr"); |
| var cipherText32 = hexStringToUint8Array("f9ba1161a16c9fcc726a4531c1b520925e"); |
| var cipherText64 = hexStringToUint8Array("f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b"); |
| var cipherText96 = hexStringToUint8Array("f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f3"); |
| var cipherText104 = hexStringToUint8Array("f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f34e"); |
| var cipherText112 = hexStringToUint8Array("f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f34e1f"); |
| var cipherText120 = hexStringToUint8Array("f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f34e1f3b"); |
| var cipherText128 = hexStringToUint8Array("f9ba1161a16c9fcc726a4531c1b520925e4ba35f8b534c62f34e1f3ba1"); |
| |
| crypto.subtle.importKey("raw", rawKey, "aes-gcm", extractable, ["decrypt"]).then(function(result) { |
| key = result; |
| |
| return crypto.subtle.decrypt({ name: "aes-gcm", iv: iv, tagLength: 32 }, key, cipherText32); |
| }).then(function(result) { |
| plainText = result; |
| shouldBe("bytesToASCIIString(plainText)", "expectedPlainText"); |
| |
| return crypto.subtle.decrypt({ name: "aes-gcm", iv: iv, tagLength: 64 }, key, cipherText64); |
| }).then(function(result) { |
| plainText = result; |
| shouldBe("bytesToASCIIString(plainText)", "expectedPlainText"); |
| |
| return crypto.subtle.decrypt({ name: "aes-gcm", iv: iv, tagLength: 96 }, key, cipherText96); |
| }).then(function(result) { |
| plainText = result; |
| shouldBe("bytesToASCIIString(plainText)", "expectedPlainText"); |
| |
| return crypto.subtle.decrypt({ name: "aes-gcm", iv: iv, tagLength: 104 }, key, cipherText104); |
| }).then(function(result) { |
| plainText = result; |
| shouldBe("bytesToASCIIString(plainText)", "expectedPlainText"); |
| |
| return crypto.subtle.decrypt({ name: "aes-gcm", iv: iv, tagLength: 112 }, key, cipherText112); |
| }).then(function(result) { |
| plainText = result; |
| shouldBe("bytesToASCIIString(plainText)", "expectedPlainText"); |
| |
| return crypto.subtle.decrypt({ name: "aes-gcm", iv: iv, tagLength: 120 }, key, cipherText120); |
| }).then(function(result) { |
| plainText = result; |
| shouldBe("bytesToASCIIString(plainText)", "expectedPlainText"); |
| |
| return crypto.subtle.decrypt({ name: "aes-gcm", iv: iv, tagLength: 128 }, key, cipherText128); |
| }).then(function(result) { |
| plainText = result; |
| shouldBe("bytesToASCIIString(plainText)", "expectedPlainText"); |
| |
| finishJSTest(); |
| }); |
| |
| </script> |
| |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |