Files
leaudit-platform-frontend/scripts/generate-jwt-secret.js
T

27 lines
1023 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* JWT Secret 生成工具
*
* 用法:
* node scripts/generate-jwt-secret.js
*
* 生成一个强随机的 JWT Secret,可以直接用于 .env 文件
*/
const crypto = require('crypto');
// 生成 64 字节(128 个十六进制字符)的强随机密钥
const secret = crypto.randomBytes(64).toString('hex');
console.log('\n==================== JWT Secret 生成成功 ====================\n');
console.log('请将以下内容添加到你的 .env 文件中:\n');
console.log(`JWT_SECRET=${secret}\n`);
console.log('⚠️ 重要提醒:');
console.log('1. 不要将此密钥提交到版本控制系统(Git)');
console.log('2. 生产环境请使用密钥管理服务(如 AWS Secrets Manager');
console.log('3. 不同环境(开发/测试/生产)应使用不同的密钥');
console.log('4. 建议每 3-6 个月轮换一次密钥');
console.log('5. 密钥长度: 128 个字符(64 字节)\n');
console.log('============================================================\n');