hmac-export-key.html 1.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<!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 exporting an AES key.");

jsTestIsAsync = true;

var extractable = true;

var jwkKey = {
    "kty": "oct",
    "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
};

ap@apple.com's avatar
ap@apple.com committed
23
var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(jwkKey));
24 25 26 27 28 29 30 31 32

debug("Importing a JWK key...");
crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", hash: "SHA-512" }, extractable, ["sign", "verify"]).then(function(result) {
    key = result;

    debug("Exporting the key as raw data...");
    return crypto.subtle.exportKey("raw", key);
}).then(function(result) {
    exportedData = result;
ap@apple.com's avatar
ap@apple.com committed
33
    shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'6a18e49feff7f3b7e09ec89b7f6deab2f6a18e49feff7f3b7e09ec89b7f6deab'");
34 35 36 37 38 39 40 41

    finishJSTest();
});
</script>

<script src="../../resources/js-test-post.js"></script>
</body>
</html>