Created
November 22, 2020 17:43
-
-
Save utkarsh-UK/808fb25c0043c39720c6977fad86ebc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> saveUserToken(String token) async { | |
try { | |
//BOX_NAME is any string key for you box name. | |
final secureKey = Hive.generateSecureKey(); | |
final encryptedBox = await Hive.openBox(BOX_NAME, encryptionKey: secureKey); | |
await encryptedBox.put('token', token); | |
//SECURE_STORAGE_KEY is any string key. | |
await secureStorage.write( | |
key: SECURE_STORAGE_KEY, | |
value: json.encode(secureKey), | |
); | |
} on Exception catch (e) { | |
throw CacheException(message: e.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment