flnxi-Wu/scripts/deploy/encrypt-password.ps1
WuYongJie f646b71813
Some checks failed
CI Check / check (push) Has been cancelled
chore: 初始化本地仓库并同步最近改动
2025-11-18 17:50:16 +08:00

44 lines
1.6 KiB
PowerShell
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.

# 加密密码脚本
# 使用方法: .\encrypt-password.ps1
param(
[Parameter(Mandatory=$true)]
[string]$PlainPassword,
[string]$OutputFile = "deploy-password.encrypted"
)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " 密码加密工具" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
try {
# 将明文密码转换为 SecureString
$securePassword = ConvertTo-SecureString -String $PlainPassword -AsPlainText -Force
# 加密 SecureString(使用 Windows Data Protection API)
$encryptedPassword = $securePassword | ConvertFrom-SecureString
# 保存到文件
$encryptedPassword | Out-File -FilePath $OutputFile -Encoding UTF8 -Force
Write-Host "✓ 密码已加密并保存到: $OutputFile" -ForegroundColor Green
Write-Host ""
Write-Host "重要提示:" -ForegroundColor Yellow
Write-Host " 1. 请妥善保管加密文件: $OutputFile" -ForegroundColor Gray
Write-Host " 2. 不要将加密文件提交到 Git 仓库" -ForegroundColor Gray
Write-Host " 3. 加密文件只能在当前用户下解密" -ForegroundColor Gray
Write-Host " 4. 如果忘记密码,需要重新加密" -ForegroundColor Gray
Write-Host ""
Write-Host "使用方法:" -ForegroundColor Yellow
Write-Host " .\deploy-optimized.ps1 -EncryptedPasswordFile `"$OutputFile`"" -ForegroundColor Gray
Write-Host ""
} catch {
Write-Host "错误: 密码加密失败" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
exit 1
}