hive icon indicating copy to clipboard operation
hive copied to clipboard

encryption - where is the best place to store encryption keys?

Open FetFrumos opened this issue 3 years ago • 0 comments

I used hive in my flutter app. I store very important data in the local database(hive). I used encryptedBox for my data, but I want to securely protect my data. so I have a few questions:

  1. I am concerned that it is relatively easy to access the box file. how reliable is the encryption method(AES-256)?

2.if the encryption is reliable(and I read that yes), then it is important to store the key securely. where is the best place to store keys? I have two options: 2.1 secureStorage(like as example).

  const secureStorage = FlutterSecureStorage();

  final encryptionKey = await secureStorage.read(key: 'key');

  if (encryptionKey == null) {

   final key = Hive.generateSecureKey();

   await secureStorage.write(    key: 'key',      value: base64UrlEncode(key),);

  }

 final key = await secureStorage.read(key: 'key');

 final encryptionKey = base64Url.decode(key!);

  final encryptedBox= await Hive.openBox('vaultBox', encryptionCipher: HiveAesCipher(encryptionKey));`

also in the documentation it says:

Only values are encrypted while keys are stored in plaintext.

I think it is not very reliable - to store the key in the program code.

2.2 store them(value and key) on the server - receive them when starting the application.

your opinion? I will be grateful for any advice.

FetFrumos avatar Sep 12 '22 16:09 FetFrumos