Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert keepass generated password into plain text #196

Open
dennisa72295 opened this issue Jun 11, 2021 · 1 comment
Open

Convert keepass generated password into plain text #196

dennisa72295 opened this issue Jun 11, 2021 · 1 comment

Comments

@dennisa72295
Copy link

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

  • [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropSe ...
  •   + CategoryInfo          : NotSpecified: (:) [], MethodException
      + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
    
@dennisa95
Copy link

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()
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants