UNPKG

pooja-docucomb-tink-crypto

Version:

A multi-language, cross-platform library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.

28 lines (24 loc) 660 B
/** * @license * Copyright 2020 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * @fileoverview Several simple wrappers of crypto.getRandomValues. */ import {InvalidArgumentsException} from '../exception/invalid_arguments_exception'; /** * Randomly generates `n` bytes. * * @param n number of bytes to generate * @return the random bytes * @static */ export function randBytes(n: number): Uint8Array { if (!Number.isInteger(n) || n < 0) { throw new InvalidArgumentsException('n must be a nonnegative integer'); } const result = new Uint8Array(n); crypto.getRandomValues(result); return result; }