You won't be able to decrypt the example string on your machine that easily because Windows uses the local user and machine account to "encrypt" the password. This process uses the Windows Data Protection API - DPAPI. If you need to use ConvertFrom-SecureString
or ConvertTo-SecureString
across multiple machines/accounts, which I wouldn't advise, then you would have to specify a key (see the parameters of the functions). Where do you then secure the key? Well...
The article is just an example of how to use it. You can copy and paste the following two code blocks to sample it without doing any file checking or further copying and pasting.
$SecureString = Read-Host -Prompt "Enter your Password" -AsSecureString
$EncryptedString = ConvertFrom-SecureString $SecureString
$EncryptedString | Out-File .\Clowns.txt # Because who would look inside, right?
To get the password back out in to a usable credential variable like the article, you'd do this.
$EncryptedString = Get-Content .\Clowns.txt
$SecureString = ConvertTo-SecureString $EncryptedString
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList "username",$SecureString
Another option, here is to use Export-Clixml
to save credential files, which carries out the same DPAPI operation on a set of credentials.
$SecureString = Read-Host -Prompt "Enter your Password" -AsSecureString
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList "username",$SecureString
$Credential | Export-Clixml -Path .\Dolphins.xml # Horrible, horrible beings.
You can then use Import-Clixml
to recover the credentials with the same user account that "encrypted" them on the same machine.
$Credential = Import-Clixml -Path .\Dolphins.xml
If this is for just keeping credentials for yourself locally, it's not a terrible option. If it's for anything else, I would prefer some password vault that you can securely use via code.