mirror of
				https://github.com/hackku21/loc-chain-app.git
				synced 2025-06-13 12:54:05 +00:00 
			
		
		
		
	added initial RSA keypair generation
This commit is contained in:
		
							parent
							
								
									25c77260f2
								
							
						
					
					
						commit
						5bff5a0c42
					
				| @ -1,113 +1,20 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:loc_chain_app/widgets/navbar.dart'; | ||||
| 
 | ||||
| void main() { | ||||
|   runApp(MyApp()); | ||||
|   runApp(App()); | ||||
| } | ||||
| 
 | ||||
| class MyApp extends StatelessWidget { | ||||
| class App extends StatelessWidget { | ||||
|   // This widget is the root of your application. | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return MaterialApp( | ||||
|       title: 'Flutter Demo', | ||||
|       theme: ThemeData( | ||||
|         // This is the theme of your application. | ||||
|         // | ||||
|         // Try running your application with "flutter run". You'll see the | ||||
|         // application has a blue toolbar. Then, without quitting the app, try | ||||
|         // changing the primarySwatch below to Colors.green and then invoke | ||||
|         // "hot reload" (press "r" in the console where you ran "flutter run", | ||||
|         // or simply save your changes to "hot reload" in a Flutter IDE). | ||||
|         // Notice that the counter didn't reset back to zero; the application | ||||
|         // is not restarted. | ||||
|         primarySwatch: Colors.blue, | ||||
|         primarySwatch: Colors.lightBlue, | ||||
|       ), | ||||
|       home: MyHomePage(title: 'Flutter Demo Home Page'), | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| class MyHomePage extends StatefulWidget { | ||||
|   MyHomePage({Key key, this.title}) : super(key: key); | ||||
| 
 | ||||
|   // This widget is the home page of your application. It is stateful, meaning | ||||
|   // that it has a State object (defined below) that contains fields that affect | ||||
|   // how it looks. | ||||
| 
 | ||||
|   // This class is the configuration for the state. It holds the values (in this | ||||
|   // case the title) provided by the parent (in this case the App widget) and | ||||
|   // used by the build method of the State. Fields in a Widget subclass are | ||||
|   // always marked "final". | ||||
| 
 | ||||
|   final String title; | ||||
| 
 | ||||
|   @override | ||||
|   _MyHomePageState createState() => _MyHomePageState(); | ||||
| } | ||||
| 
 | ||||
| class _MyHomePageState extends State<MyHomePage> { | ||||
|   int _counter = 0; | ||||
| 
 | ||||
|   void _incrementCounter() { | ||||
|     setState(() { | ||||
|       // This call to setState tells the Flutter framework that something has | ||||
|       // changed in this State, which causes it to rerun the build method below | ||||
|       // so that the display can reflect the updated values. If we changed | ||||
|       // _counter without calling setState(), then the build method would not be | ||||
|       // called again, and so nothing would appear to happen. | ||||
|       _counter++; | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     // This method is rerun every time setState is called, for instance as done | ||||
|     // by the _incrementCounter method above. | ||||
|     // | ||||
|     // The Flutter framework has been optimized to make rerunning build methods | ||||
|     // fast, so that you can just rebuild anything that needs updating rather | ||||
|     // than having to individually change instances of widgets. | ||||
|     return Scaffold( | ||||
|       appBar: AppBar( | ||||
|         // Here we take the value from the MyHomePage object that was created by | ||||
|         // the App.build method, and use it to set our appbar title. | ||||
|         title: Text(widget.title), | ||||
|       ), | ||||
|       body: Center( | ||||
|         // Center is a layout widget. It takes a single child and positions it | ||||
|         // in the middle of the parent. | ||||
|         child: Column( | ||||
|           // Column is also a layout widget. It takes a list of children and | ||||
|           // arranges them vertically. By default, it sizes itself to fit its | ||||
|           // children horizontally, and tries to be as tall as its parent. | ||||
|           // | ||||
|           // Invoke "debug painting" (press "p" in the console, choose the | ||||
|           // "Toggle Debug Paint" action from the Flutter Inspector in Android | ||||
|           // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) | ||||
|           // to see the wireframe for each widget. | ||||
|           // | ||||
|           // Column has various properties to control how it sizes itself and | ||||
|           // how it positions its children. Here we use mainAxisAlignment to | ||||
|           // center the children vertically; the main axis here is the vertical | ||||
|           // axis because Columns are vertical (the cross axis would be | ||||
|           // horizontal). | ||||
|           mainAxisAlignment: MainAxisAlignment.center, | ||||
|           children: <Widget>[ | ||||
|             Text( | ||||
|               'You have pushed the button this many times:', | ||||
|             ), | ||||
|             Text( | ||||
|               '$_counter', | ||||
|               style: Theme.of(context).textTheme.headline4, | ||||
|             ), | ||||
|           ], | ||||
|         ), | ||||
|       ), | ||||
|       floatingActionButton: FloatingActionButton( | ||||
|         onPressed: _incrementCounter, | ||||
|         tooltip: 'Increment', | ||||
|         child: Icon(Icons.add), | ||||
|       ), // This trailing comma makes auto-formatting nicer for build methods. | ||||
|       home: NavBarWidget(), | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  | ||||
							
								
								
									
										52
									
								
								loc_chain_app/lib/pages/home.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								loc_chain_app/lib/pages/home.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| 
 | ||||
| class HomePage extends StatefulWidget { | ||||
|   HomePage({Key key, this.title}) : super(key: key); | ||||
|   final String title; | ||||
| 
 | ||||
|   @override | ||||
|   _HomePageState createState() => _HomePageState(); | ||||
| } | ||||
| 
 | ||||
| class _HomePageState extends State<HomePage> { | ||||
|   int _counter = 0; | ||||
| 
 | ||||
|   void _incrementCounter() { | ||||
|     setState(() { | ||||
|       // This call to setState tells the Flutter framework that something has | ||||
|       // changed in this State, which causes it to rerun the build method below | ||||
|       // so that the display can reflect the updated values. If we changed | ||||
|       // _counter without calling setState(), then the build method would not be | ||||
|       // called again, and so nothing would appear to happen. | ||||
|       _counter++; | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return Scaffold( | ||||
|       appBar: AppBar( | ||||
|         title: Text(widget.title), | ||||
|       ), | ||||
|       body: Center( | ||||
|         child: Column( | ||||
|           mainAxisAlignment: MainAxisAlignment.center, | ||||
|           children: <Widget>[ | ||||
|             Text( | ||||
|               'You have pushed the button this many times:', | ||||
|             ), | ||||
|             Text( | ||||
|               '$_counter', | ||||
|               style: Theme.of(context).textTheme.headline4, | ||||
|             ), | ||||
|           ], | ||||
|         ), | ||||
|       ), | ||||
|       floatingActionButton: FloatingActionButton( | ||||
|         onPressed: _incrementCounter, | ||||
|         tooltip: 'Increment', | ||||
|         child: Icon(Icons.add), | ||||
|       ), | ||||
|     ); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										89
									
								
								loc_chain_app/lib/pages/keygen.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								loc_chain_app/lib/pages/keygen.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,89 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flutter/services.dart'; | ||||
| import 'package:rsa_encrypt/rsa_encrypt.dart' as rsa; | ||||
| import 'package:pointycastle/api.dart' as crypto; | ||||
| 
 | ||||
| class KeygenPage extends StatefulWidget { | ||||
|   KeygenPage({Key key, this.title}) : super(key: key); | ||||
|   final String title; | ||||
| 
 | ||||
|   @override | ||||
|   _KeygenState createState() => _KeygenState(); | ||||
| } | ||||
| 
 | ||||
| class _KeygenState extends State<KeygenPage> { | ||||
|   static crypto.AsymmetricKeyPair _keyPair; | ||||
| 
 | ||||
|   void _regenerateKey() { | ||||
|     setState(() { | ||||
|       _keyPair = rsa.getRsaKeyPair(rsa.RsaKeyHelper().getSecureRandom()); | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   String _getPublicKey() { | ||||
|     if (_keyPair == null) | ||||
|       return 'Press the button below to generate your key pair!'; | ||||
|     return '${rsa.RsaKeyHelper().encodePublicKeyToPemPKCS1(_keyPair.publicKey)}'; | ||||
|   } | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     // This method is rerun every time setState is called, for instance as done | ||||
|     // by the _incrementCounter method above. | ||||
|     // | ||||
|     // The Flutter framework has been optimized to make rerunning build methods | ||||
|     // fast, so that you can just rebuild anything that needs updating rather | ||||
|     // than having to individually change instances of widgets. | ||||
|     return Scaffold( | ||||
|       appBar: AppBar( | ||||
|         // Here we take the value from the MyHomePage object that was created by | ||||
|         // the App.build method, and use it to set our appbar title. | ||||
|         title: Text('RSA Key Configuration'), | ||||
|       ), | ||||
|       body: Center( | ||||
|         // Center is a layout widget. It takes a single child and positions it | ||||
|         // in the middle of the parent. | ||||
|         child: Column( | ||||
|           // Column is also a layout widget. It takes a list of children and | ||||
|           // arranges them vertically. By default, it sizes itself to fit its | ||||
|           // children horizontally, and tries to be as tall as its parent. | ||||
|           // | ||||
|           // Invoke "debug painting" (press "p" in the console, choose the | ||||
|           // "Toggle Debug Paint" action from the Flutter Inspector in Android | ||||
|           // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) | ||||
|           // to see the wireframe for each widget. | ||||
|           // | ||||
|           // Column has various properties to control how it sizes itself and | ||||
|           // how it positions its children. Here we use mainAxisAlignment to | ||||
|           // center the children vertically; the main axis here is the vertical | ||||
|           // axis because Columns are vertical (the cross axis would be | ||||
|           // horizontal). | ||||
|           mainAxisAlignment: MainAxisAlignment.center, | ||||
|           children: <Widget>[ | ||||
|             TextButton( | ||||
|               onPressed: () => Clipboard.setData( | ||||
|                 new ClipboardData( | ||||
|                   text: _getPublicKey(), | ||||
|                 ), | ||||
|               ).then((_) { | ||||
|                 ScaffoldMessenger.of(context).showSnackBar(SnackBar( | ||||
|                   content: Text("RSA public key copied to keyboard"), | ||||
|                 )); | ||||
|               }), | ||||
|               child: Text( | ||||
|                 _getPublicKey(), | ||||
|                 style: Theme.of(context).textTheme.bodyText1, | ||||
|               ), | ||||
|               style: Theme.of(context).outlinedButtonTheme.style, | ||||
|             ), | ||||
|             ElevatedButton( | ||||
|               onPressed: _regenerateKey, | ||||
|               child: Text('Reset RSA Key'), | ||||
|               style: Theme.of(context).elevatedButtonTheme.style, | ||||
|             ), | ||||
|           ], | ||||
|         ), | ||||
|       ), | ||||
|     ); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										50
									
								
								loc_chain_app/lib/widgets/navbar.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								loc_chain_app/lib/widgets/navbar.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,50 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:loc_chain_app/pages/home.dart'; | ||||
| import 'package:loc_chain_app/pages/keygen.dart'; | ||||
| 
 | ||||
| class NavBarWidget extends StatefulWidget { | ||||
|   NavBarWidget({Key key}) : super(key: key); | ||||
| 
 | ||||
|   @override | ||||
|   _NavBarWidgetState createState() => _NavBarWidgetState(); | ||||
| } | ||||
| 
 | ||||
| class _NavBarWidgetState extends State<NavBarWidget> { | ||||
|   int _selectedIndex = 0; | ||||
|   StatefulWidget _selectedWidget; | ||||
|   static List<Widget> pages = <Widget>[ | ||||
|     HomePage( | ||||
|       title: 'Home', | ||||
|     ), | ||||
|     KeygenPage( | ||||
|       title: 'RSA Configuration', | ||||
|     ), | ||||
|   ]; | ||||
|   void _onItemTapped(int index) => setState(() { | ||||
|         _selectedIndex = index; | ||||
|         _selectedWidget = pages[_selectedIndex]; | ||||
|       }); | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(context) => Scaffold( | ||||
|         body: _selectedWidget, | ||||
|         bottomNavigationBar: BottomNavigationBar( | ||||
|           items: const <BottomNavigationBarItem>[ | ||||
|             BottomNavigationBarItem( | ||||
|               icon: Icon(Icons.home_rounded), | ||||
|               label: 'Home', | ||||
|               backgroundColor: Colors.cyan, | ||||
|             ), | ||||
|             BottomNavigationBarItem( | ||||
|               icon: Icon(Icons.lock_rounded), | ||||
|               label: 'RSA Configuration', | ||||
|               backgroundColor: Colors.cyan, | ||||
|             ), | ||||
|           ], | ||||
|           currentIndex: _selectedIndex, | ||||
|           selectedItemColor: Colors.lightBlueAccent, | ||||
|           unselectedItemColor: Colors.lightBlue[200], | ||||
|           onTap: _onItemTapped, | ||||
|         ), | ||||
|       ); | ||||
| } | ||||
| @ -1,6 +1,13 @@ | ||||
| # Generated by pub | ||||
| # See https://dart.dev/tools/pub/glossary#lockfile | ||||
| packages: | ||||
|   asn1lib: | ||||
|     dependency: transitive | ||||
|     description: | ||||
|       name: asn1lib | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "0.8.1" | ||||
|   async: | ||||
|     dependency: transitive | ||||
|     description: | ||||
| @ -88,6 +95,20 @@ packages: | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "1.8.0" | ||||
|   pointycastle: | ||||
|     dependency: transitive | ||||
|     description: | ||||
|       name: pointycastle | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "2.0.1" | ||||
|   rsa_encrypt: | ||||
|     dependency: "direct main" | ||||
|     description: | ||||
|       name: rsa_encrypt | ||||
|       url: "https://pub.dartlang.org" | ||||
|     source: hosted | ||||
|     version: "1.0.5" | ||||
|   sky_engine: | ||||
|     dependency: transitive | ||||
|     description: flutter | ||||
|  | ||||
| @ -28,6 +28,7 @@ dependencies: | ||||
|   # The following adds the Cupertino Icons font to your application. | ||||
|   # Use with the CupertinoIcons class for iOS style icons. | ||||
|   cupertino_icons: ^1.0.2 | ||||
|   rsa_encrypt: ^1.0.5 | ||||
| 
 | ||||
| dev_dependencies: | ||||
|   flutter_test: | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user