[Powershell]Obfuscate password

This is a sample script to create a password file, the file is encrypted, however when you need to read from the files you can use it for your script to authenticate so that your script do not need to hardcode the password in plaintext.

$username = "Your_Username"
if ((Test-Path .\password.do) -eq $true) {
    $password = Get-Content ".\password.do" | ConvertTo-SecureString
    $credential = New-Object System.Management.Automation.PSCredential($username,$password)
    } else {
        Read-Host $username -AsSecureString | ConvertFrom-SecureString | Out-File .\password.do
        $password = Get-Content .\password.do | ConvertTo-SecureString
        $credential = New-Object System.Management.Automation.PSCredential($username,$password)
        }
    #$credential.GetNetworkCredential().Password

The credential.GetNetworkCredential().Password will display your encrypted password in plaintext.

This is how password.do looks like:
01000000d08c9ddf0115d1118c7a00c04fc297eb01000000beaf1d362eb1554e96ec3bb2ef9eb7370000000002000000000003660000c000000010000000776a63452de2b5e91bc47f520c2afd1c0000000004800000a000000010000000f971fb271a0c8cf18462794bd9ea709e180000002bf88317c82ecac4c3cbb3c41a7d6f9a4859f67bd65cc56f1400000009a7a391fb283c2829032351cf51f8988801fac8

Advertisements
This entry was posted in Powershell, Scripting and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s