Skip to content

Instantly share code, notes, and snippets.

@kiwi-cam
Last active July 31, 2018 00:31
Show Gist options
  • Save kiwi-cam/20ad4ff5b1b271d4947cf860b4dbef3e to your computer and use it in GitHub Desktop.
Save kiwi-cam/20ad4ff5b1b271d4947cf860b4dbef3e to your computer and use it in GitHub Desktop.
PowerShell includes tools to Encrypt and Decrypt strings. Because we're not supplying a Key, they're encrypted using Windows Data Protection API (DPAPI) meaning the string can only be decrypted on the computer used to encrypt them. These one line commands can be used to output to file, then recover the password securely
'Powershell OneLiner to encrypt a password to file:
' ConvertTo-SecureString -String "ThisIsMySecurePassword" -AsPlainText -Force | ConvertFrom-SecureString > .\Password.txt
'Powershell OneLiner to decrypt that password
' (New-Object PSCredential "user",(ConvertTo-SecureString (Get-Content .\Password.txt))).GetNetworkCredential().Password
'You could then embed this into VBScript so the password is not stored in the script
'powershell.exe -NonInteractive -NoLogo -Command "(New-Object PSCredential 'user',(ConvertTo-SecureString (Get-Content .\Desktop\Password.txt))).GetNetworkCredential().Password"
Set oShell = WScript.CreateObject("WScript.Shell")
Set oExec = oShell.Exec("powershell.exe -NonInteractive -NoLogo -Command ""(New-Object PSCredential 'user',(ConvertTo-SecureString (Get-Content .\Desktop\Password.txt))).GetNetworkCredential().Password""")
WScript.Echo oExec.StdOut.ReadLine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment