mirror of
https://github.com/danbulant/jose
synced 2026-05-25 13:01:49 +00:00
14 lines
421 B
JavaScript
14 lines
421 B
JavaScript
const { randomBytes, createSecretKey } = require('crypto')
|
|
|
|
const OctKey = require('../jwk/key/oct')
|
|
const KEYLENGTHS = require('../help/key_lengths')
|
|
|
|
module.exports = (alg) => {
|
|
const byteLength = KEYLENGTHS[alg] / 8
|
|
|
|
if (byteLength === undefined) {
|
|
throw new TypeError('unsupported intended content encryption key alg')
|
|
}
|
|
|
|
return new OctKey(createSecretKey(randomBytes(byteLength)), { use: 'enc', alg })
|
|
}
|