4 <script src=
"../../../resources/js-test.js"></script>
5 <script src=
"../resources/common.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
12 description("Test unwrapping an HKDF key");
16 kHkdfKey
= hexStringToUint8Array("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
17 kIv
= new Uint8Array(16);
19 var extractable
= true;
20 var derivingKeyAlgorithm
= {
23 salt
: new Uint8Array(),
24 info
: new Uint8Array()
27 Promise
.resolve(null).then(function(result
) {
28 // Create a key to use for wrapping/unwrapping
29 return crypto
.subtle
.generateKey({name
: "AES-GCM", length
: 256}, false, ['encrypt', 'unwrapKey']);
30 }).then(function(result
) {
33 shouldEvaluateAs("wrappingKey.algorithm.name", "AES-GCM");
34 shouldEvaluateAs("wrappingKey.extractable", false);
35 shouldEvaluateAs("wrappingKey.usages.join(',')", "encrypt,unwrapKey");
37 // Wrap the HKDF key. Since the HKDF algorithm does not support the export
38 // key operation, it is wrapped by calling encrypt.
39 return crypto
.subtle
.encrypt({name
: "AES-GCM", length
: 256, iv
: kIv
}, wrappingKey
, kHkdfKey
);
40 }).then(function(result
) {
43 // Unwrap it as a raw key.
44 return crypto
.subtle
.unwrapKey("raw", wrappedKey
, wrappingKey
, {name
: "AES-GCM", length
: 256, iv
: kIv
}, "HKDF", false, ['deriveBits']);
45 }).then(function(result
) {
46 unwrappedHkdfKey
= result
;
48 shouldEvaluateAs("unwrappedHkdfKey.algorithm.name", "HKDF");
49 shouldEvaluateAs("unwrappedHkdfKey.extractable", false);
50 shouldEvaluateAs("unwrappedHkdfKey.usages.join(',')", "deriveBits");
52 debug("\nUnwrap an HKDF key using pkcs8 as the format.");
53 return crypto
.subtle
.unwrapKey("pkcs8", wrappedKey
, wrappingKey
, {name
: "AES-GCM", length
: 256, iv
: kIv
}, "HKDF", false, ['deriveBits']);
54 }).then(failAndFinishJSTest
, function(result
) {
56 }).then(finishJSTest
, failAndFinishJSTest
);