Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
Created April 1, 2016 20:44
Show Gist options
  • Select an option

  • Save gregjhogan/c563282edc98ff50279fb64c02fc4803 to your computer and use it in GitHub Desktop.

Select an option

Save gregjhogan/c563282edc98ff50279fb64c02fc4803 to your computer and use it in GitHub Desktop.
local machine (vs user) encryption/decryption
Add-Type -Assembly System.Security
$password = "secret"
# encrypt
$encrypted = [System.Security.Cryptography.ProtectedData]::Protect([System.Text.Encoding]::UTF8.GetBytes($password), $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine)
[System.Convert]::ToBase64String($encrypted) | Out-File "password.txt" -Encoding UTF8
# decrypt
$encrypted = [System.Convert]::FromBase64String((Get-Content "password.txt"))
$password = [System.Text.Encoding]::UTF8.GetString([System.Security.Cryptography.ProtectedData]::Unprotect($encrypted, $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment