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
846 B

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