| <!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&decrypting using AES-GCM algorithm with a generated 256bit key"); |
| |
| jsTestIsAsync = true; |
| var plainText = "Hello, World!"; |
| var aesGcmParams = { |
| name: "aes-gcm", |
| iv: asciiToUint8Array("jnOw99oOZFLIEPMr"), |
| } |
| |
| debug("Generating a key..."); |
| crypto.subtle.generateKey({name: "aes-gcm", length: 256}, true, ["decrypt", "encrypt"]).then(function(result) { |
| key = result; |
| debug("Encrypting..."); |
| return crypto.subtle.encrypt(aesGcmParams, key, asciiToUint8Array(plainText)); |
| }).then(function(result) { |
| cipherText = result; |
| shouldNotBeEqualToString("bytesToASCIIString(cipherText)", plainText); |
| debug("Decrypting..."); |
| return crypto.subtle.decrypt(aesGcmParams, key, cipherText); |
| }).then(function(result) { |
| decryptedText = result; |
| |
| shouldBe("bytesToASCIIString(decryptedText)", "plainText"); |
| |
| finishJSTest(); |
| }); |
| </script> |
| |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |