Add functionality to generate and retrieve file encryption keys

This commit is contained in:
Vishnu Mohandas 2020-08-10 02:09:33 +05:30
parent f80e06762f
commit 87a5c519ba

View file

@ -1,3 +1,4 @@
import 'package:photos/utils/crypto_util.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Configuration {
@ -9,6 +10,7 @@ class Configuration {
static const _usernameKey = "username";
static const _userIDKey = "user_id";
static const _passwordKey = "password";
static const _keyKey = "key";
SharedPreferences _preferences;
@ -63,6 +65,15 @@ class Configuration {
await _preferences.setString(_passwordKey, password);
}
void generateAndSaveKey(String passphrase) async {
final key = CryptoUtil.createCryptoRandomString();
await _preferences.setString(_keyKey, CryptoUtil.encrypt(key, passphrase));
}
String getKey(String passphrase) {
return CryptoUtil.decrypt(_preferences.getString(_keyKey), passphrase);
}
bool hasConfiguredAccount() {
return getEndpoint() != null && getToken() != null;
}