44 lines
1.6 KiB
PowerShell
44 lines
1.6 KiB
PowerShell
# 加密密码脚本
|
||
# 使用方法: .\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
|
||
}
|
||
|