Created
August 15, 2018 08:47
-
-
Save mpomery/6872c959147e3e4e86f6bdefb0c85fba to your computer and use it in GitHub Desktop.
DPAPI Encryption/Decryption
This file contains 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
function Get-DpapiEncryptedValue([string] $valueToEncrypt) { | |
Add-Type -AssemblyName System.Security | |
$clearBytes = [System.Text.Encoding]::UTF8.GetBytes($valueToEncrypt) | |
$encryptedBytes = [System.Security.Cryptography.ProtectedData]::Protect($clearBytes, $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine) | |
return [System.Convert]::ToBase64String($encryptedBytes) | |
} | |
function Get-DpapiDecryptedValue([string] $valueToDecrypt) { | |
Add-Type -AssemblyName System.Security | |
$clearBytes = [System.Convert]::FromBase64String($valueToDecrypt) | |
$decryptedBytes = [System.Security.Cryptography.ProtectedData]::Unprotect($clearBytes, $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine) | |
return [System.Text.Encoding]::UTF8.GetString($decryptedBytes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment