這段程式碼的主要功能是解密之前加密過的憑證私鑰密碼,並將解密後的結果顯示在控制台上。以下是程式碼各部分的功能說明:
# 定義解密函數
function Decrypt-Password {
param (
[string]$KeyFilePath,
[string]$EncryptedPasswordFilePath
)
Write-Host "解密憑證私鑰密碼..."
$Key = [System.Convert]::FromBase64String((Get-Content $KeyFilePath))
$EncryptedPassword = Get-Content -Path $EncryptedPasswordFilePath
$SecurePassword = ConvertTo-SecureString -String $EncryptedPassword -Key $Key
$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword))
Write-Host "憑證私鑰密碼已成功解密: $Password" -ForegroundColor Green
}
# 解密證書私鑰密碼
Decrypt-Password -KeyFilePath $KeyFilePath -EncryptedPasswordFilePath $EncryptedPasswordFilePath
參考資料:
ChatGPT 問答測試結果