updated keygen to conform with backend

This commit is contained in:
Zachary Atkins 2021-04-11 00:58:10 -05:00
parent 8c2dc2a1b7
commit be205fddc8
2 changed files with 14 additions and 11 deletions

View File

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:fast_rsa/rsa.dart'; import 'package:openpgp/openpgp.dart';
import 'package:fast_rsa/model/bridge.pb.dart'; import 'package:openpgp/model/bridge.pb.dart';
import 'package:loc_chain_app/util/keyfile_manager.dart'; import 'package:loc_chain_app/util/keyfile_manager.dart';
@ -25,13 +25,18 @@ class _KeygenState extends State<KeygenPage> {
if (!keyPair.hasPublicKey()) { if (!keyPair.hasPublicKey()) {
initKeyPair(); initKeyPair();
} else { } else {
setState(() => _keyPair = keyPair); setState(() {
_keyPair.publicKey = keyPair.publicKey;
_keyPair.privateKey = keyPair.privateKey;
});
} }
}); });
} }
Future<void> initKeyPair() async { Future<void> initKeyPair() async {
var keyPair = await RSA.generate(2048); var options = KeyOptions()..rsaBits = 2048;
var keyPair =
await OpenPGP.generate(options: Options()..keyOptions = options);
await KeyFileManager.writeKeyPair(keyPair); await KeyFileManager.writeKeyPair(keyPair);
setState(() { setState(() {
_keyPair = keyPair; _keyPair = keyPair;
@ -64,7 +69,7 @@ class _KeygenState extends State<KeygenPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('RSA Key Configuration'), title: Text('PGP Key Configuration'),
), ),
body: Center( body: Center(
child: LayoutBuilder( child: LayoutBuilder(
@ -85,7 +90,7 @@ class _KeygenState extends State<KeygenPage> {
), ),
ElevatedButton( ElevatedButton(
onPressed: initKeyPair, onPressed: initKeyPair,
child: Text('Reset RSA Key'), child: Text('Reset PGP Key'),
style: Theme.of(context).elevatedButtonTheme.style, style: Theme.of(context).elevatedButtonTheme.style,
), ),
], ],

View File

@ -1,4 +1,4 @@
import 'package:fast_rsa/model/bridge.pb.dart'; import 'package:openpgp/model/bridge.pb.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'dart:io'; import 'dart:io';
@ -31,10 +31,8 @@ class KeyFileManager {
String pubKey = await _pubKeyFile.then( String pubKey = await _pubKeyFile.then(
(file) => file.readAsString(), (file) => file.readAsString(),
); );
keyPair = KeyPair( keyPair.publicKey = pubKey;
privateKey: privKey, keyPair.privateKey = privKey;
publicKey: pubKey,
);
return keyPair; return keyPair;
} catch (e) { } catch (e) {
print(e); print(e);