| <!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 RSAES-PKCS1-v1_5 algorithm with a generated key"); |
| |
| jsTestIsAsync = true; |
| var plainText = "Hello, World!"; |
| var algorithmKeyGen = { |
| name: "RSAES-PKCS1-v1_5", |
| // RsaKeyGenParams |
| modulusLength: 2048, |
| publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 |
| }; |
| |
| debug("Generating a key..."); |
| crypto.subtle.generateKey(algorithmKeyGen, true, ["decrypt", "encrypt"]).then(function(result) { |
| keyPair = result; |
| debug("Encrypting..."); |
| return crypto.subtle.encrypt("RSAES-PKCS1-v1_5", keyPair.publicKey, asciiToUint8Array(plainText)); |
| }).then(function(result) { |
| cipherText = result; |
| shouldNotBeEqualToString("bytesToASCIIString(cipherText)", plainText); |
| debug("Decrypting..."); |
| return crypto.subtle.decrypt("RSAES-PKCS1-v1_5", keyPair.privateKey, cipherText); |
| }).then(function(result) { |
| decryptedText = result; |
| |
| shouldBe("bytesToASCIIString(decryptedText)", "plainText"); |
| |
| finishJSTest(); |
| }); |
| </script> |
| |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |