According to the doc a simple example to derive a password with PBKDF2 is
return window.crypto.subtle.importKey(
'raw',
encoder.encode(password),
{name: 'PBKDF2'},
false,
['deriveBits', 'deriveKey']
).then(function(key) {
return window.crypto.subtle.deriveKey(
{ "name": 'PBKDF2',
"salt": encoder.encode(salt),
"iterations": iterations,
"hash": 'SHA-256'
},
key,
{ "name": 'AES-CTR', "length": 128 }, //api requires this to be set
true, //extractable
[ "encrypt", "decrypt" ] //allowed functions
)
}).then(function (webKey) {
return crypto.subtle.exportKey("raw", webKey);
})
As one can see the API lets you choose:
- key derivation function (and it's underlying hash)
- salt
- iterations
- raw key material (ie. password)
However as far as I can see there is no options for choosing the out-length. It seems that the cipher suite parameter { "name": 'AES-CTR', "length": 128 }
influences the out length, but you can only choose 16 and 32 byte.
For example with 10,000 rounds, salt: 'salt', password: 'key material' with 128 it will result in the following 16 bytes:
26629f0e2b7b14ed4b84daa8071c648c
whereas with { "name": 'AES-CTR', "length": 256 }
you will get
26629f0e2b7b14ed4b84daa8071c648c648d2cce067f93e2c5bde0c620030521
How do I set the out length apart from 16 or 32 byte? Do I have to truncate it myself?