且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将安全字符串转换为纯文本

更新时间:2021-12-04 23:15:38

您很接近,但是您传递给SecureStringToBSTR的参数必须为SecureString.您似乎正在传递ConvertFrom-SecureString的结果,该结果是加密的标准字符串.因此,在传递给SecureStringToBSTR之前,先对此调用ConvertTo-SecureString.

You are close, but the parameter you pass to SecureStringToBSTR must be a SecureString. You appear to be passing the result of ConvertFrom-SecureString, which is an encrypted standard string. So call ConvertTo-SecureString on this before passing to SecureStringToBSTR.

$SecurePassword = ConvertTo-SecureString $PlainPassword -AsPlainText -Force
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)