Convert a secure string to plain text

后端 未结 4 834
滥情空心
滥情空心 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:19

    The easiest way to convert back it in PowerShell

    [System.Net.NetworkCredential]::new("", $SecurePassword).Password
    
    0 讨论(0)
  • 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)
    
    0 讨论(0)
  • 2020-11-28 04:24

    You may also use PSCredential.GetNetworkCredential() :

    $SecurePassword = Get-Content C:\Users\tmarsh\Documents\securePassword.txt | ConvertTo-SecureString
    $UnsecurePassword = (New-Object PSCredential "user",$SecurePassword).GetNetworkCredential().Password
    
    0 讨论(0)
  • 2020-11-28 04:24

    In PS 7, you can use ConvertFrom-SecureString and -AsPlainText:

     $UnsecurePassword = ConvertFrom-SecureString -SecureString $SecurePassword -AsPlainText
    

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/ConvertFrom-SecureString?view=powershell-7#parameters

    ConvertFrom-SecureString
               [-SecureString] <SecureString>
               [-AsPlainText]
               [<CommonParameters>]
    
    0 讨论(0)
提交回复
热议问题