1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-03 23:50:33 +02:00
Files
joplin/packages/utils/crypto.ts

10 lines
327 B
TypeScript
Raw Normal View History

/* eslint-disable import/prefer-default-export */
import { randomBytes } from 'crypto';
export const getSecureRandomString = (length: number): string => {
const bytes = randomBytes(Math.ceil(length * 2));
const randomString = bytes.toString('base64').replace(/[^a-zA-Z0-9]/g, '');
return randomString.slice(0, length);
};