I have such a code. But I am getting _CastError (Null check operator used on a null value) error in the codes.
const secureStorage = FlutterSecureStorage();
final encryprionKey = secureStorage.read(key: 'key');
if (encryprionKey == 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!);
print('Encryption key: $encryptionKey');
final encryptedBox= await Hive.openBox('vaultBox', encryptionCipher:
HiveAesCipher(encryptionKey));
encryptedBox.put('secret', 'Hive is cool');
print(encryptedBox.get('secret'));
How can I solve it?
