loadSecureStorage method
Fonction permettant le chargement et déchiffrement du SecureStorage
Implementation
bool loadSecureStorage(){
logger("$secStorageInitDebugHeader - SecureStorage was set");
if (_secureStorageKey == null || _secureStorageIV == null){
// TODO - Add better error handling
throw Exception("Secure storage was marked as set but no marks of it on the host system");
}
else{
_encryptedSecureStorageKey = Key.fromUtf8(_secureStorageKey!);
_encrypter = Encrypter(AES(_encryptedSecureStorageKey!));
File storageFile = File(SECURE_STORAGE_PATH);
if (!storageFile.existsSync()){
logger("$secStorageInitDebugHeader - key file does not exist, creating it");
storageFile.createSync();
_data = {};
return true;
}
else{
storageFile.openRead();
Uint8List encryptedContent = storageFile.readAsBytesSync();
if (encryptedContent.isEmpty){
_secureStorageReadStatus = true;
return true;
}
String data = utf8.decode(_encrypter!.decryptBytes(Encrypted(encryptedContent), iv: _secureStorageIV!));
Map<String,dynamic> res = jsonDecode(data);
_secureStorageReadStatus = true;
_data = res.cast();
logger("$secStorageInitDebugHeader - Data resssemble to this ${_data}");
return true;
}
}
}