mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-08 18:03:12 +00:00
34 lines
1.1 KiB
Dart
34 lines
1.1 KiB
Dart
|
import 'dart:developer';
|
||
|
|
||
|
import 'package:hive/hive.dart';
|
||
|
import 'package:pointycastle/pointycastle.dart';
|
||
|
import 'package:rsa_encrypt/rsa_encrypt.dart';
|
||
|
import 'package:selfprivacy/config/hive_config.dart';
|
||
|
import 'package:pointycastle/api.dart' as crypto;
|
||
|
import 'package:ssh_key/ssh_key.dart' as ssh_key;
|
||
|
|
||
|
class SSHModel {
|
||
|
Box _box = Hive.box(BNames.sshConfig);
|
||
|
String? savedPrivateKey;
|
||
|
String? savedPubKey;
|
||
|
|
||
|
Future<void> generateKeys() async {
|
||
|
var helper = RsaKeyHelper();
|
||
|
crypto.AsymmetricKeyPair pair =
|
||
|
await helper.computeRSAKeyPair(helper.getSecureRandom());
|
||
|
var privateKey = pair.privateKey as RSAPrivateKey;
|
||
|
var publicKey = pair.publicKey as RSAPublicKey;
|
||
|
|
||
|
savedPrivateKey = helper.encodePrivateKeyToPemPKCS1(privateKey);
|
||
|
savedPubKey = publicKey.encode(ssh_key.PubKeyEncoding.openSsh);
|
||
|
|
||
|
await _box.put(BNames.sshPrivateKey, savedPrivateKey);
|
||
|
await _box.put(BNames.sshPublicKey, savedPubKey);
|
||
|
}
|
||
|
|
||
|
void init() {
|
||
|
savedPrivateKey = _box.get(BNames.sshPrivateKey);
|
||
|
savedPubKey = _box.get(BNames.sshPublicKey);
|
||
|
}
|
||
|
}
|