PowerShell - Decode System.Security.SecureString to readable password

后端 未结 4 1755
既然无缘
既然无缘 2020-11-29 07:09

I want to decode the password from a System.Security.SecureString to a readable password.

$password = convertto-securestring \"TestPassword\" -asplaintext -f         


        
4条回答
  •  执笔经年
    2020-11-29 08:00

    For a "System.Net.NetworkCredential" object, all you need to do is read the String password.

    $password = convertto-securestring "TestPassword" -asplaintext -force
    $credentials = New-Object System.Net.NetworkCredential("TestUsername", $password, "TestDomain")
    $credentials.Password
    TestPassword
    
    $credentials | gm
    
    TypeName: System.Net.NetworkCredential
    
    Name           MemberType Definition
    ----           ---------- ----------
    Equals         Method     bool Equals(System.Object obj)
    GetCredential  Method     System.Net.NetworkCredential GetCredential(uri uri, str
    GetHashCode    Method     int GetHashCode()
    GetType        Method     type GetType()
    ToString       Method     string ToString()
    Domain         Property   string Domain {get;set;}
    Password       Property   string Password {get;set;}
    SecurePassword Property   securestring SecurePassword {get;set;}
    UserName       Property   string UserName {get;set;}
    

    If you end up with a PSCredential object, from an interactive command like Get-Credential use

    $credentials=Get-Credential
    $credentials.GetNetworkCredential().UserName
    TestUsername
    $credentials.GetNetworkCredential().Domain
    TestDomain
    $credentials.GetNetworkCredential().Password
    TestPassword
    

    See http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/26/decrypt-powershell-secure-string-password.aspx for details.

    Note: I used PS 4 for this example.

提交回复
热议问题