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); } void unsetPrivateKey() async { final prefs = await SharedPreferences.getInstance(); await prefs.remove(rsaPrivateKeyName); } Future 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); }