|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import "package:pointycastle/export.dart";
|
|
import '/utils/encryption/crypto_utils.dart';
|
|
|
|
const rsaPrivateKeyName = 'rsaPrivateKey';
|
|
|
|
void setPrivateKey(RSAPrivateKey key) async {
|
|
String keyPem = CryptoUtils.encodeRSAPrivateKeyToPem(key);
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
prefs.setString(rsaPrivateKeyName, keyPem);
|
|
}
|
|
|
|
void unsetPrivateKey() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.remove(rsaPrivateKeyName);
|
|
}
|
|
|
|
Future<RSAPrivateKey> getPrivateKey() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
String? keyPem = prefs.getString(rsaPrivateKeyName);
|
|
if (keyPem == null) {
|
|
throw Exception('No RSA private key set');
|
|
}
|
|
|
|
return CryptoUtils.rsaPrivateKeyFromPem(keyPem);
|
|
}
|