$Passphrase=Read-Host ‘Enter the secret pass phrase’
$Path=”$env:temp\secret.txt”
$key=[Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
try
{
$decryptedTextSecureString=Get-Content -Path $Path -Raw |
ConvertTo-SecureString -Key $key -ErrorAction Stop
$cred=New-Object -TypeName System.Management.Automation.PSCredential(‘dummy’, $decryptedTextSecureString)
$decryptedText=$cred.GetNetworkCredential().Password
}
catch
{
$decryptedText='(wrong key)’
}
“The decrypted secret text: $decryptedText”
© 版权声明
文章版权归作者所有,未经允许请勿转载。