PoShKeePass icon indicating copy to clipboard operation
PoShKeePass copied to clipboard

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

Open sgreci opened this issue 4 years ago • 2 comments

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

sgreci avatar Jan 28 '21 12:01 sgreci

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

  •     $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.

marayas avatar May 13 '21 17:05 marayas

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

emichnie avatar May 27 '21 18:05 emichnie