iv.js 607 B

1234567891011121314151617181920
  1. import { JOSENotSupported } from '../util/errors.js';
  2. import random from '../runtime/random.js';
  3. export function bitLength(alg) {
  4. switch (alg) {
  5. case 'A128GCM':
  6. case 'A128GCMKW':
  7. case 'A192GCM':
  8. case 'A192GCMKW':
  9. case 'A256GCM':
  10. case 'A256GCMKW':
  11. return 96;
  12. case 'A128CBC-HS256':
  13. case 'A192CBC-HS384':
  14. case 'A256CBC-HS512':
  15. return 128;
  16. default:
  17. throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
  18. }
  19. }
  20. export default (alg) => random(new Uint8Array(bitLength(alg) >> 3));