putStringList method
Method to set StringList in local storage
key
-> Key for key-value pair
isEncrypted
-> Flag whether to encrypt or not
val
-> Value for key-value pair
Implementation
Future<void> putStringList(String key, List<String> val, bool isEncrypted) async {
_assetFunction(isEncrypted);
if (isEncrypted) {
if (Platform.isAndroid) {
_secureStorage?.write(key: key, value: val.toString());
} else if (Platform.isIOS) {
if (await _isMasterKeyAvailable() && _areSubKeysAvailable()) {
final keys = await _getEncrypterKeys();
final algorithm = _getAlgorithm();
final encryptedKey = await algorithm.encrypt(key.codeUnits,
secretKey: SecretKey(keys.first[SuperSecureSharedPref.keyForKey]!), nonce: keys.first[SuperSecureSharedPref.ivForKey]);
final encryptedValue = await algorithm.encrypt(val.toString().codeUnits,
secretKey: SecretKey(keys.last[SuperSecureSharedPref.keyForKey]!), nonce: keys.last[SuperSecureSharedPref.ivForKey]);
_sharedPreferences.setString(encryptedKey.cipherText.toString(), encryptedValue.cipherText.toString());
} else {
if (await _isMasterKeyAvailable() && _areSubKeysAvailable() == false) {
await _deleteMasterKey();
}
var masterKey = await _createMasterKey();
await _saveMasterKeyToKeychain(masterKey);
await _generateAndSaveKeyAndValueSubKeys(await _getMasterKeyFromKeyChain());
putStringList(key, val, isEncrypted);
}
} else {
throw PlatformException(message: "Not Supported for ${Platform.operatingSystem} platform", code: "501");
}
} else {
_sharedPreferences.setStringList(key, val);
}
}