Add functionality to generate and retrieve file encryption keys
This commit is contained in:
parent
f80e06762f
commit
87a5c519ba
1 changed files with 11 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue