Convert a secure string to plain text

后端 未结 4 853
滥情空心
滥情空心 2020-11-28 03:39

I\'m working in PowerShell and I have code that successfully converts a user entered password into plain text:

$SecurePassword = Read-Host -AsSecureString  \         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 04:21

    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)
    

提交回复
热议问题