File size: 327 Bytes
eb846d0
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
export function generateRandomKey(length: number = 32): string {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  const array = new Uint8Array(length);
  crypto.getRandomValues(array);
  return Array.from(array)
    .map((x) => characters.charAt(x % characters.length))
    .join('');
}