File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ using System . Text . Json ;
2+ using EccSDK . models ;
3+
4+ namespace EccSDK ;
5+
6+ public static class KeyStorageHelper
7+ {
8+ private const string KeysPath = "~/keys.json" ;
9+
10+ public static KeyStorageData LoadKeyPair ( )
11+ {
12+ if ( File . Exists ( KeysPath ) )
13+ {
14+ return RestoreKeys ( ) ;
15+ }
16+
17+ var keyStorageData = new KeyStorageData
18+ {
19+ KeyPair = EccGenerator . GenerateKeyPair ( 256 ) ,
20+ SessionKey = SessionKeyGenerator . GenerateSessionKey ( )
21+ } ;
22+
23+ keyStorageData . SaveKeys ( KeysPath ) ;
24+
25+ return keyStorageData ;
26+ }
27+
28+ private static KeyStorageData RestoreKeys ( )
29+ {
30+ var keyData = File . ReadAllText ( KeysPath ) ;
31+ return JsonSerializer . Deserialize < KeyStorageData > ( keyData ) ! ;
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ using System . Text . Json ;
2+
3+ namespace EccSDK . models ;
4+
5+ public class KeyStorageData
6+ {
7+ public KeyPair KeyPair { get ; set ; }
8+ public SessionKey SessionKey { get ; set ; }
9+
10+ public void SaveKeys ( string keyPath )
11+ {
12+ var keyWithJson = JsonSerializer . Serialize ( this ) ;
13+ File . WriteAllText ( keyPath , keyWithJson ) ;
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments