PSKeePass / PoShKeePass

PowerShell module for KeePass
MIT License
255 stars 56 forks source link

The composite key is invalid! Make sure the composite key is correct and try again #191

Open sgreci opened 3 years ago

sgreci commented 3 years ago

Hello, i'm testing PoShKeePass with key files. I've created through the KeePass 2 windows interface a new database and configured the access only with a keyfile.

I created a KeePassDatabaseConfiguration:

New-KeePassDatabaseConfiguration -DatabasePath "C:\Projects\keepass\database1.kdbx" -DatabaseProfileName "profile1" -KeyPath "C:\Projects\keepass\database1.keyx"

and this is the result:

PS C:\Users\sgrec> Get-KeePassDatabaseConfiguration

DatabasePath       : C:\Projects\keepass\database1.kdbx
Default            : False
Name               : profile1
UseMasterKey       : False
KeyPath            : C:\Projects\keepass\database1.keyx
AuthenticationType : Key
UseNetworkAccount  : False

When i try to open the database and read an entry i got this error:

PS C:\Users\sgrec> Get-KeePassEntry -Title "localhost_user1" -DatabaseProfileName profile1
Exception calling "Open" with "3" argument(s): "The composite key is invalid!
Make sure the composite key is correct and try again."
At C:\Program Files\WindowsPowerShell\Modules\PoShKeePass\2.1.3.0\PoShKeePass.psm1:2664 char:9
+         $null = $DatabaseObject.Open($IOInfo, $CompositeKey, $IStatus ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidCompositeKeyException

InvalidDatabaseConnectionException : The database is not open.
At C:\Program Files\WindowsPowerShell\Modules\PoShKeePass\2.1.3.0\PoShKeePass.psm1:2669 char:13
+             Throw 'InvalidDatabaseConnectionException : The database  ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (InvalidDatabase...se is not open.:String) [], RuntimeException
    + FullyQualifiedErrorId : InvalidDatabaseConnectionException : The database is not open.

Really don't understand what's going on because from KeePass 2 GUI I can open the database and read/write entries. Here below my versions:

Name                           Value
----                           -----
PSVersion                      5.1.19041.610
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.610
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

KeePass 2 2.47 PoShKeePass 2.1.3.0

marayas commented 3 years ago

Same issue for me, but I'm not using a keyfile.

1.- If i pass the password manually it works 2.- If i used the System.Security.SecureString doesn't work and get the same error

PS D:\gdlrayas\GitLab\marco-wintel-scripts> Get-KeePassEntry -DatabaseProfileName 'TEST' -MasterKey $PWord Exception calling "Open" with "3" argument(s): "The composite key is invalid! Make sure the composite key is correct and try again." At C:\Program Files\WindowsPowerShell\Modules\PoShKeePass\2.1.3.0\PoShKeePass.psm1:2664 char:9

InvalidDatabaseConnectionException : The database is not open. At C:\Program Files\WindowsPowerShell\Modules\PoShKeePass\2.1.3.0\PoShKeePass.psm1:2669 char:13

emichnie commented 3 years ago

I had similar issue. My initial keyfile, I've generated using Format version 2.0(recommended). However, when I've generated new keyfile using Format Version 1.0(compatible with older KeePass version/ports) I was able to use PoShKeePass with keyfile. KeyFile-FormatVersion-1