aes-cbc-wrap-rsa.html 1.8 KB
Newer Older
ap@apple.com's avatar
ap@apple.com committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<!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 wrapping an RSA key with AES-CBC.");

jsTestIsAsync = true;

var extractable = true;
var nonExtractable = false;

var publicKeyJSON = {
    kty: "RSA",
    alg: "RS256",
    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
    e: "AQAB",
24
    ext: true,
ap@apple.com's avatar
ap@apple.com committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    use: "sig"
};

var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(publicKeyJSON));
var wrappingKeyOctets = hexStringToUint8Array("2a00e0e776e94e4dc89bf947cebdebe1");

debug("Importing a key to wrap...");
crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, null, extractable, ["sign", "verify"]).then(function(result) {
    key = result;
    shouldBe("key.algorithm.name", "'rsassa-pkcs1-v1_5'");
    debug("Importing a key encryption key...");
    return crypto.subtle.importKey("raw", wrappingKeyOctets, "AES-CBC", nonExtractable, ["wrapKey"]);
}).then(function(result) {
    wrappingKey = result;
    shouldBe("wrappingKey.algorithm.name", "'aes-cbc'");
    var wrapAlgorithm = {name: "AES-CBC", iv: hexStringToUint8Array("000102030405060708090a0b0c0d0e0f")};
    return crypto.subtle.wrapKey("jwk", key, wrappingKey, wrapAlgorithm);
}).then(function(result) {
    wrappedKey = result;
    shouldBe("wrappedKey.toString()", "'[object ArrayBuffer]'");
    finishJSTest();
});

</script>

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