jose/lib/jwe/generate_iv.js
2019-01-26 14:24:12 +01:00

20 lines
426 B
JavaScript

const { randomBytes } = require('crypto')
const IVLENGTHS = {
'A128CBC-HS256': 128 / 8,
'A192CBC-HS384': 128 / 8,
'A256CBC-HS512': 128 / 8,
'A128GCM': 96 / 8,
'A192GCM': 96 / 8,
'A256GCM': 96 / 8
}
module.exports = (alg) => {
const byteLength = IVLENGTHS[alg]
if (byteLength === undefined) {
throw new TypeError('unsupported intended content encryption key alg')
}
return randomBytes(byteLength)
}