1
+ import 'dart:convert' ;
1
2
import 'package:cryptography_plus/cryptography_plus.dart' ;
2
3
import 'package:flutter_secure_storage/flutter_secure_storage.dart' ;
3
4
@@ -20,12 +21,13 @@ class KeyService {
20
21
final publicKey = await keyPair.extractPublicKey ();
21
22
await _secureStorage.write (
22
23
key: 'privateKey' ,
23
- value: String . fromCharCodes (privateKey),
24
+ value: base64. encode (privateKey),
24
25
);
25
26
await _secureStorage.write (
26
27
key: 'publicKey' ,
27
- value: String . fromCharCodes (publicKey.bytes),
28
+ value: base64. encode (publicKey.bytes),
28
29
);
30
+ await _secureStorage.write (key: 'migrated' , value: 'true' );
29
31
}
30
32
31
33
Future saveKeyId (String keyId) async {
@@ -38,8 +40,28 @@ class KeyService {
38
40
if (privateKeyString == null || publicKeyString == null ) {
39
41
return null ;
40
42
}
41
- final privateKey = privateKeyString.codeUnits;
42
- final publicKey = publicKeyString.codeUnits;
43
+ final migrated = await _secureStorage.read (key: 'migrated' );
44
+ if (migrated == null ) {
45
+ final privateKey = privateKeyString.codeUnits;
46
+ final publicKey = publicKeyString.codeUnits;
47
+
48
+ await _secureStorage.write (
49
+ key: 'privateKey' ,
50
+ value: base64.encode (privateKey),
51
+ );
52
+ await _secureStorage.write (
53
+ key: 'publicKey' ,
54
+ value: base64.encode (publicKey),
55
+ );
56
+ await _secureStorage.write (key: 'migrated' , value: 'true' );
57
+ return SimpleKeyPairData (
58
+ privateKey,
59
+ publicKey: SimplePublicKey (publicKey, type: KeyPairType .ed25519),
60
+ type: KeyPairType .ed25519,
61
+ );
62
+ }
63
+ final privateKey = base64.decode (privateKeyString);
64
+ final publicKey = base64.decode (publicKeyString);
43
65
return SimpleKeyPairData (
44
66
privateKey,
45
67
publicKey: SimplePublicKey (publicKey, type: KeyPairType .ed25519),
0 commit comments