INNER CODE UNIT · JavaScript
checkKeyLength
DinoChiesa/jwt-webtool · src/js/app.js:489
function checkKeyLength(alg, exact, keybuffer) {
const length = keybuffer.byteLength,
requiredLength = requiredKeyBitsForAlg(alg) / 8,
okResult = exact ? length == requiredLength : length >= requiredLength;
if (okResult) return Promise.resolve(keybuffer);
const errorMsg = exact
? `inappropriate key length, provided=${length}, required=${requiredLength}`
: `insufficient key length. You need at least ${requiredLength} bytes to use ${alg}`;
return Promise.reject(new Error(errorMsg));
}
function retrieveCryptoKey(header, options) {
// options = {direction:'encrypt'} or {direction:'decrypt'}
// When using symmetric keys and algorithms, it does not matter.
if (pbes2KeyEncryptionAlgs.indexOf(header.alg) >= 0) {
// overwrite the header values with values from the inputs
header.p2c = getPbkdf2IterationCount();
header.p2s = getPbkdf2SaltBuffer().toString("base64");