isar / isar/hive

Open box using wrong password issue

Open
#926 0 comments 0 reactions 0 assignees View on GitHub
problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Steps to Reproduce**
Just run below code, see comment.

**Code sample**
```
////////// 1. Open a new box, write something into it
var box1 = await Hive.openBox(
"testBox",
encryptionCipher: HiveAesCipher(sha256.convert(utf8.encode("000")).bytes),
crashRecovery: false,
);

debugPrint("# isOpen: ${box1.isOpen}");

await box1.put('name', 'David');
debugPrint('# Name: ${box1.get('name')}');

await box1.close();

////////// 2. Use wrong password to open it
try {
var box2 = await Hive.openBox(
"testBox",
encryptionCipher: HiveAesCipher(sha256.convert(utf8.encode("111")).bytes),
crashRecovery: false,
);

debugPrint("# isOpen: ${box2.isOpen}");
} catch (e) {
debugPrint(e.toString()); // It will fail, this is expected.
}

////////// 3. Use wrong password to try again.
try {
var box3 = await Hive.openBox(
"testBox",
encryptionCipher: HiveAesCipher(sha256.convert(utf8.encode("111")).bytes),
crashRecovery: false,
);

debugPrint("# isOpen: ${box3.isOpen}"); // Open successfully, this is unexpected.
} catch (e) {
debugPrint(e.toString()); // Should get same error here as step 2
}
```

**Version**
- Platform: Windows, Android Emulator
- Flutter version: 2.10.2
- Hive version: 2.0.6

**Temporary fix**
Hive.close(); // Can be fixed by using this method to clear internal _boxes HashMap when got wrong password error

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the supplied reproduction against Hive.openBox and compare the first and second attempts with the wrong password. Inspect the internal _boxes HashMap mentioned in the temporary fix; done means retrying with the wrong password fails consistently without requiring Hive.close().

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
databases, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.