PSKeePass / PoShKeePass

PowerShell module for KeePass
MIT License
256 stars 58 forks source link

Convert keepass generated password into plain text #196

Open dennisa72295 opened 3 years ago

dennisa72295 commented 3 years ago

I've issued this command: $pwd= New-KeePassPassword -UpperCase -LowerCase -Digits -ExcludeLookAlike -Length 20

Now I want to see what was generated before I insert it into my keepass database. How do I do that? I've tried this and you can see the error I get:

[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd) ) Cannot convert argument "s", with value: "KeePassLib.Security.ProtectedString", for "SecureStringToBSTR" to type "System.Security.SecureString": "Cannot convert the "KeePassLib.Security.ProtectedString" value of type "KeePassLib.Security.ProtectedString" to type "System.Security.SecureString"." At line:1 char:1

dennisa95 commented 3 years ago

Found a function that will do what I wanted: function ConvertFrom-KPProtectedString { <* .SYNOPSIS This function will Convert a KeePass ProtectedString to Plain Text. .DESCRIPTION This function will convert a KeePassLib.Security.ProtectedString to plain text This would primarily be used for reading Title, Username, Password, Notes and URL ProtectedString values. .EXAMPLE PS>Get-KeePassPassword -UpperCase -LowerCase -Digits -SpecialCharacters -Length 21 | ConvertFrom-KeePassProtectedString This example will create a password using the specified options and convert the resulting password to a string .PARAMETER KeePassProtectedString This is the KeePassLib.Security.ProtectedString to be converted to plain text

>

[CmdletBinding()] [OutputType([String])] param ( [Parameter(Position = 0, Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] [ValidateNotNull ()] [KeePassLib.Security.ProtectedString] $KeePassProtectedString ) process { $KeePassProtectedString.ReadString() } }