mirror of
https://github.com/danbulant/jose
synced 2026-05-24 20:41:46 +00:00
23 lines
495 B
JavaScript
23 lines
495 B
JavaScript
const { randomBytes } = require('crypto')
|
|
|
|
const IVLENGTHS = {
|
|
'A128CBC-HS256': 128 / 8,
|
|
'A128GCM': 96 / 8,
|
|
'A128GCMKW': 96 / 8,
|
|
'A192CBC-HS384': 128 / 8,
|
|
'A192GCM': 96 / 8,
|
|
'A192GCMKW': 96 / 8,
|
|
'A256CBC-HS512': 128 / 8,
|
|
'A256GCM': 96 / 8,
|
|
'A256GCMKW': 96 / 8
|
|
}
|
|
|
|
module.exports = (alg) => {
|
|
const byteLength = IVLENGTHS[alg]
|
|
|
|
if (byteLength === undefined) {
|
|
throw new TypeError('unsupported intended content encryption key alg')
|
|
}
|
|
|
|
return randomBytes(byteLength)
|
|
}
|