generateSecureId (security/secure-random.ts)

ruflo · v3/@claude-flow/shared/src/security/secure-random.ts · typescript · MIT
security, tag:knn-classified

* Secure Random Utilities Cryptographically secure random ID and token generation. Replaces Math.random() for security-sensitive operations. @module v3/shared/security/secure-random /

// Source: https://github.com/ruvnet/ruflo | License: MIT | Copyright 2024-2026 ruvnet
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Secure Random Utilities
 *
 * Cryptographically secure random ID and token generation.
 * Replaces Math.random() for security-sensitive operations.
 *
 * @module v3/shared/security/secure-random
 */

import { randomBytes, randomUUID } from 'crypto';

/**
 * Generate a cryptographically secure random ID
 * @param prefix Optional prefix for the ID
 * @param length Number of random bytes (default 12)
 * @returns Secure random ID string
 */
export function generateSecureId(prefix?: string, length: number = 12): string {
  const timestamp = Date.now().toString(36);
  const randomPart = randomBytes(length).toString('hex');
  return prefix 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key