|
|
- import 'package:shared_preferences/shared_preferences.dart';
- import "package:pointycastle/export.dart";
- import '/utils/encryption/rsa_key_helper.dart';
-
- const rsaPrivateKeyName = 'rsaPrivateKey';
-
- void setPrivateKey(RSAPrivateKey key) async {
- String keyPem = RsaKeyHelper.encodePrivateKeyToPem(key);
-
- final prefs = await SharedPreferences.getInstance();
- prefs.setString(rsaPrivateKeyName, keyPem);
- }
-
- 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 RsaKeyHelper.parsePrivateKeyFromPem(keyPem);
- }
|