Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
849 B

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<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);
}