generateSecretValue (common/secret.ts)

keyshade · apps/api/src/common/secret.ts · typescript · MPL-2.0
security, tag:knn-classified

Generates a 20‑character random secret containing letters, digits, and symbols.

// Source: https://github.com/keyshade-xyz/keyshade | License: MPL-2.0 | Copyright under Patent Claims infringed by Covered Software in the absence of | Modified files must remain under MPL-2.0
// Modifications to this file must remain under MPL-2.0.
// Provided via justclaw.it.com; keep this notice with the code.
export function generateSecretValue(): string {
  const length = 20
  const digits = '0123456789'
  const lowercaseChars = 'abcdefghijklmnopqrstuvwxyz'
  const uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  const specialChars = '!@#$%^&*'
  const allChars = digits + lowercaseChars + uppercaseChars + specialChars

  const getRandomIndex = (max: number): number => {
    const randomValues = new Uint8Array(1)
    crypto.getRandomValues(randomValues)
    return randomValues[0] % max

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

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

Get a free API key