(prefix: string, length: number = 24)
| 1 | import * as crypto from 'crypto'; |
| 2 | |
| 3 | export function randomKey(prefix: string, length: number = 24): string { |
| 4 | while (true) { |
| 5 | const randomBytesBuffer = crypto.randomBytes(length * 2); |
| 6 | const normalized = randomBytesBuffer.toString('base64').replace(/[^a-zA-Z0-9]/g, ''); |
| 7 | if (normalized.length < length) continue; |
| 8 | return `${prefix}_${normalized.slice(0, length)}`; |
| 9 | } |
| 10 | } |
nothing calls this directly
no outgoing calls
no test coverage detected