41 lines
1.5 KiB
PowerShell
41 lines
1.5 KiB
PowerShell
# 解密密码脚本(用于测试)
|
|
# 使用方法: .\decrypt-password.ps1 -EncryptedPasswordFile "deploy-password.encrypted"
|
|
|
|
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$EncryptedPasswordFile
|
|
)
|
|
|
|
if (-not (Test-Path $EncryptedPasswordFile)) {
|
|
Write-Host "错误: 加密文件不存在: $EncryptedPasswordFile" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
try {
|
|
# 从文件读取加密的密码
|
|
$encryptedPassword = Get-Content -Path $EncryptedPasswordFile -Raw
|
|
|
|
# 转换为 SecureString
|
|
$securePassword = $encryptedPassword | ConvertTo-SecureString
|
|
|
|
# 创建 PSCredential 对象来获取明文密码(仅用于测试)
|
|
$credential = New-Object System.Management.Automation.PSCredential("user", $securePassword)
|
|
$plainPassword = $credential.GetNetworkCredential().Password
|
|
|
|
Write-Host "密码已解密(仅用于测试):" -ForegroundColor Yellow
|
|
Write-Host $plainPassword -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "警告: 请勿在生产环境中使用此脚本!" -ForegroundColor Red
|
|
|
|
} catch {
|
|
Write-Host "错误: 密码解密失败" -ForegroundColor Red
|
|
Write-Host $_.Exception.Message -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "可能的原因:" -ForegroundColor Yellow
|
|
Write-Host " 1. 加密文件损坏" -ForegroundColor Gray
|
|
Write-Host " 2. 加密文件是在其他用户下创建的" -ForegroundColor Gray
|
|
Write-Host " 3. 加密文件是在其他计算机上创建的" -ForegroundColor Gray
|
|
exit 1
|
|
}
|
|
|