function decrypt([string]$Passphrase,[string]$cryptText){
$key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
$decryptedTextSecureString = $cryptText |
ConvertTo-SecureString -Key $key -ErrorAction Stop
$cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedTextSecureString)
$decryptedText = $cred.GetNetworkCredential().Password
return $decryptedText
}
function encrypt([string]$Passphrase,[string]$plainText){
$key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
$cryptText = $plainText | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $key
return $cryptText
}
【无标题】
于 2022-10-11 17:14:19 首次发布