⚠️ 網站服務遷移公告 (System Alert)
🚀 新版發布:IIS SSL 自動化腳本 V6 (完整版)
您目前觀看的是舊版本教學。為了提升安全性與自動化穩定度,我已釋出最新的 V6 完整版,整合了 AES 加密與自動解密流程。
👉 點此前往:[PowerShell] IIS SSL 憑證自動更新全攻略 (V6)(包含完整原始碼、加密設定與排程教學)
這段程式碼的主要功能是解密之前加密過的憑證私鑰密碼,並將解密後的結果顯示在控制台上。以下是程式碼各部分的功能說明:
-
Decrypt-Password 函數:
- 接受兩個參數:
$KeyFilePath(存儲加密金鑰的文件路徑) 和$EncryptedPasswordFilePath(存儲加密後密碼的文件路徑)。 - 從指定的
$KeyFilePath讀取加密金鑰。 - 從
$EncryptedPasswordFilePath中讀取加密過的密碼。 - 使用從檔案讀取的加密金鑰來對加密後的密碼進行解密,得到安全字串 (
SecureString)。 - 將安全字串轉換為普通字串 (
$Password),以便於顯示或後續使用。
- 接受兩個參數:
-
解密證書私鑰密碼:
- 呼叫
Decrypt-Password函數,並將加密金鑰文件路徑 ($KeyFilePath) 和加密後密碼文件路徑 ($EncryptedPasswordFilePath) 作為參數傳遞進去。 - 函數會解密指定的加密密碼文件,並將解密後的私鑰密碼顯示在控制台上,同時以綠色文字標記操作成功的訊息。
- 呼叫
這段程式碼與前面的加密函數結合使用,允許您在需要時安全地加密和解密憑證私鑰密碼,以確保敏感資訊的安全性。
# 定義解密函數
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 問答測試結果
文章標籤
全站熱搜

留言功能已依作者設定調整顯示方式