diff --git a/lib/src/kdbx_format.dart b/lib/src/kdbx_format.dart index 05887e7..caf37db 100644 --- a/lib/src/kdbx_format.dart +++ b/lib/src/kdbx_format.dart @@ -65,8 +65,8 @@ abstract class CredentialsPart { class KeyFileCredentials implements CredentialsPart { factory KeyFileCredentials(Uint8List keyFileContents) { - final keyFileAsString = utf8.decode(keyFileContents); try { + final keyFileAsString = utf8.decode(keyFileContents); if (_hexValuePattern.hasMatch(keyFileAsString)) { return KeyFileCredentials._(ProtectedValue.fromBinary( convert.hex.decode(keyFileAsString) as Uint8List)); diff --git a/test/kdbx4_test.dart b/test/kdbx4_test.dart index 378192f..c8b15bb 100644 --- a/test/kdbx4_test.dart +++ b/test/kdbx4_test.dart @@ -79,6 +79,15 @@ void main() { final pwd = firstEntry.getString(KdbxKey('Password')).getText(); expect(pwd, 'def'); }); + test('Binary Keyfile', () async { + final data = + await File('test/keyfile/BinaryKeyFilePasswords.kdbx').readAsBytes(); + final keyFile = + await File('test/keyfile/binarykeyfile.key').readAsBytes(); + final file = kdbxFormat.read(data, + Credentials.composite(ProtectedValue.fromString('asdf'), keyFile)); + expect(file.body.rootGroup.entries, hasLength(1)); + }); }); group('Writing', () { test('Create and save', () { diff --git a/test/keyfile/BinaryKeyFilePasswords.kdbx b/test/keyfile/BinaryKeyFilePasswords.kdbx new file mode 100644 index 0000000..8a24dd1 Binary files /dev/null and b/test/keyfile/BinaryKeyFilePasswords.kdbx differ diff --git a/test/keyfile/binarykeyfile.key b/test/keyfile/binarykeyfile.key new file mode 100644 index 0000000..7f8d5c8 --- /dev/null +++ b/test/keyfile/binarykeyfile.key @@ -0,0 +1 @@ +!Oœ 8!Wȸ9&78!Aw5EՐ|،ujsEn(v$6?rg:Wj/O6]mkhxWkń"x{Ijv2 \ No newline at end of file