password-gen

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Password Generation Skill

密码生成技能

Generate secure passwords and secrets.
生成安全密码与密钥。

When to Use

适用场景

  • Generate secure passwords
  • Create API keys or tokens
  • Generate random strings
  • Create secure filenames
  • Generate cryptographic nonces
  • 生成安全密码
  • 创建API密钥或令牌
  • 生成随机字符串
  • 创建安全文件名
  • 生成加密nonce

Password Generation

密码生成

Basic Password

基础密码

bash
undefined
bash
undefined

Random 16 char password

Random 16 char password

openssl rand -base64 16
openssl rand -base64 16

Random 20 char alphanumeric

Random 20 char alphanumeric

openssl rand -hex 20
openssl rand -hex 20

Using /dev/urandom

Using /dev/urandom

tr -dc 'A-Za-z0-9' </dev/urandom | head -c 20
tr -dc 'A-Za-z0-9' </dev/urandom | head -c 20

Using pwgen (if installed)

Using pwgen (if installed)

pwgen 16 1
undefined
pwgen 16 1
undefined

Secure Password with Special Chars

含特殊字符的安全密码

bash
undefined
bash
undefined

Include special characters

Include special characters

tr -dc 'A-Za-z0-9!@#$%^&*' </dev/urandom | head -c 20
tr -dc 'A-Za-z0-9!@#$%^&*' </dev/urandom | head -c 20

More secure version

More secure version

openssl rand -base64 32 | tr -dc 'A-Za-z0-9!@#$%^&*' | head -c 24
undefined
openssl rand -base64 32 | tr -dc 'A-Za-z0-9!@#$%^&*' | head -c 24
undefined

Memorable Passwords

易记密码

bash
undefined
bash
undefined

Diceware-style (using wordlist)

Diceware-style (using wordlist)

shuf -n 4 /usr/share/dict/words | tr '\n' '-'
shuf -n 4 /usr/share/dict/words | tr '\n' '-'

Using apg (if installed)

Using apg (if installed)

apg -a 1 -M Ncl
undefined
apg -a 1 -M Ncl
undefined

API Keys & Tokens

API密钥与令牌

UUID Generation

UUID生成

bash
undefined
bash
undefined

UUID v4

UUID v4

uuidgen
uuidgen

Or using Python

Or using Python

python3 -c "import uuid; print(uuid.uuid4())"
python3 -c "import uuid; print(uuid.uuid4())"

Or using node

Or using node

node -e "console.log(require('crypto').randomUUID())"
undefined
node -e "console.log(require('crypto').randomUUID())"
undefined

JWT-Style Tokens

JWT风格令牌

bash
undefined
bash
undefined

Random token (base64)

Random token (base64)

openssl rand -base64 32
openssl rand -base64 32

Hex token

Hex token

openssl rand -hex 32
undefined
openssl rand -hex 32
undefined

OAuth Secrets

OAuth密钥

bash
undefined
bash
undefined

Client secret

Client secret

openssl rand -base64 32
openssl rand -base64 32

256-bit key

256-bit key

openssl rand -hex 32
undefined
openssl rand -hex 32
undefined

Cryptographic Functions

加密函数

Hash Password

密码哈希

bash
undefined
bash
undefined

SHA-256 hash

SHA-256 hash

echo -n "password" | openssl dgst -sha256
echo -n "password" | openssl dgst -sha256

SHA-512 hash

SHA-512 hash

echo -n "password" | openssl dgst -sha512
echo -n "password" | openssl dgst -sha512

Bcrypt (using htpasswd)

Bcrypt (using htpasswd)

htpasswd -nbBC 10 user password
undefined
htpasswd -nbBC 10 user password
undefined

Generate Salt

生成盐值

bash
undefined
bash
undefined

Random salt (16 bytes hex)

Random salt (16 bytes hex)

openssl rand -hex 16
openssl rand -hex 16

Random salt (16 bytes base64)

Random salt (16 bytes base64)

openssl rand -base64 16
undefined
openssl rand -base64 16
undefined

Script Examples

脚本示例

Generate Password Script

密码生成脚本

bash
#!/bin/bash
bash
#!/bin/bash

Generate a secure password

Generate a secure password

LENGTH="${1:-16}" CHARS="${2:-A-Za-z0-9!@#$%^&*}"
openssl rand -base64 "$LENGTH" | tr -dc "$CHARS" | head -c "$LENGTH" echo
undefined
LENGTH="${1:-16}" CHARS="${2:-A-Za-z0-9!@#$%^&*}"
openssl rand -base64 "$LENGTH" | tr -dc "$CHARS" | head -c "$LENGTH" echo
undefined

Generate API Key

API密钥生成脚本

bash
#!/bin/bash
bash
#!/bin/bash

Generate API key (prefix_key format)

Generate API key (prefix_key format)

PREFIX="${1:-sk}" openssl rand -hex 32 | sed "s/^/${PREFIX}_/"
undefined
PREFIX="${1:-sk}" openssl rand -hex 32 | sed "s/^/${PREFIX}_/"
undefined

Generate All Keys

全类型密钥生成脚本

bash
#!/bin/bash
bash
#!/bin/bash

Generate full set of API credentials

Generate full set of API credentials

echo "=== API Credentials ===" echo "Client ID: $(openssl rand -hex 16)" echo "Client Secret: $(openssl rand -base64 32)" echo "API Key: sk_$(openssl rand -hex 32)" echo "JWT Secret: $(openssl rand -base64 32)" echo "" echo "=== Database ===" echo "Password: $(openssl rand -base64 16)" echo "" echo "=== Encryption ===" echo "Key: $(openssl rand -hex 32)" echo "IV: $(openssl rand -hex 16)"
undefined
echo "=== API Credentials ===" echo "Client ID: $(openssl rand -hex 16)" echo "Client Secret: $(openssl rand -base64 32)" echo "API Key: sk_$(openssl rand -hex 32)" echo "JWT Secret: $(openssl rand -base64 32)" echo "" echo "=== Database ===" echo "Password: $(openssl rand -base64 16)" echo "" echo "=== Encryption ===" echo "Key: $(openssl rand -hex 32)" echo "IV: $(openssl rand -hex 16)"
undefined

Security Notes

安全注意事项

  • Always use cryptographically secure random generators
  • Never use
    rand()
    or similar pseudo-random functions
  • Use appropriate length (min 16 for passwords, 32 for keys)
  • Store hashes, never store plain text
  • Use unique salts for each password
  • 始终使用加密安全的随机生成器
  • 切勿使用
    rand()
    或类似的伪随机函数
  • 使用合适的长度(密码至少16位,密钥至少32位)
  • 存储哈希值,绝不存储明文
  • 为每个密码使用唯一的盐值

Quick Commands

快速命令

TaskCommand
16-char password
openssl rand -base64 16 | tr -dc 'A-Za-z0-9' | head -c 16
32-char API key
openssl rand -hex 32
UUID
uuidgen
Random hex
openssl rand -hex 16
Random base64
openssl rand -base64 32
任务命令
16位密码
openssl rand -base64 16 | tr -dc 'A-Za-z0-9' | head -c 16
32位API密钥
openssl rand -hex 32
UUID
uuidgen
随机十六进制字符串
openssl rand -hex 16
随机Base64字符串
openssl rand -base64 32