Last active
July 31, 2018 00:31
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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