blob: 9af360ed76d037a42af458bb5dbe35f1dad0f3e9 [file] [log] [blame]
<!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 RSA-OAEP SHA-512 algorithm with a generated key and a label");
jsTestIsAsync = true;
var plainText = "Hello, World!";
var algorithmKeyGen = {
name: "RSA-OAEP",
// RsaKeyGenParams
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
hash: "sha-512"
};
var rsaOaepParams = {
name: "rsa-oaep",
label: asciiToUint8Array("WebKit.org"),
}
debug("Generating a key...");
crypto.subtle.generateKey(algorithmKeyGen, true, ["decrypt", "encrypt"]).then(function(result) {
keyPair = result;
debug("Encrypting...");
return crypto.subtle.encrypt(rsaOaepParams, keyPair.publicKey, asciiToUint8Array(plainText));
}).then(function(result) {
cipherText = result;
shouldNotBeEqualToString("bytesToASCIIString(cipherText)", plainText);
debug("Decrypting...");
return crypto.subtle.decrypt(rsaOaepParams, keyPair.privateKey, cipherText);
}).then(function(result) {
decryptedText = result;
shouldBe("bytesToASCIIString(decryptedText)", "plainText");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>