Last active
February 18, 2025 06:52
-
-
Save heiny/e45ea0ff0ad8e5c8d107eee665fbacef to your computer and use it in GitHub Desktop.
Revisions
-
heiny revised this gist
Aug 20, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # There is no facility to replace passwords in RDCMan once they are stored. The only way is to create a new custom credential. # If you open your *.rdg file in a text editor, locate the stored <password>, you can then decrypt it using this script. # This script can also encrypt a plain text password in rdg format which can be used to overwrite an existing one in the xml. Add-Type -AssemblyName System.Security; Function EncryptPassword { -
heiny created this gist
Aug 20, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ # There is no facility to replace passwords in RDCMan once they are stored. The only way is to create a new custom credential. # If you open your *.rdg file in a text editor, locate the stored <password>, you can then decrypt it using this script. # You can also use this script to encrypt a plain text password in the correct format, and overwrite an existing one in the xml in order to update it. Add-Type -AssemblyName System.Security; Function EncryptPassword { [CmdletBinding()] param([String]$PlainText = $null) # convert to RDCMan format: (null terminated chars) $withPadding = @() foreach($char in $PlainText.ToCharArray()) { $withPadding += [int]$char $withPadding += 0 } # encrypt with DPAPI (current user) $encrypted = [Security.Cryptography.ProtectedData]::Protect($withPadding, $null, 'CurrentUser') return $base64 = [Convert]::ToBase64String($encrypted) } Function DecryptPassword { [CmdletBinding()] param([String]$EncodedPasswordString = $null) $decoded = [Convert]::FromBase64String($EncodedPasswordString) $decryptedBytes = [Security.Cryptography.ProtectedData]::Unprotect($decoded, $null, 'CurrentUser') $decryptedString = [Text.Encoding]::ASCII.GetString($decryptedBytes) # trim null terminating chars from padding (does not account for pwds with spaces in them) $sb = [System.Text.StringBuilder]::new() foreach($char in $decryptedString.ToCharArray()) { if($char -ne 0) { $sb.Append($char) > $null } } return $sb.ToString() } # round trip test $plainText = 'AllYourPasswordsAreBelongToUs' # encrypt $encrypted = EncryptPassword($plainText) Write-Host "Encrypted Base64 Encoded PWD: $encrypted" # decrypt $decrypted = DecryptPassword($encrypted) Write-Host "Decrypted PWD: $decrypted" # assert equality if($plainText -ne $decrypted) { Write-Error "Round trip failed!" }