Skip to content

Commit 6bcd7e8

Browse files
chore: Drop archived 'encrypt' dep, use pointycastle directly (#92)
1 parent de261f6 commit 6bcd7e8

4 files changed

Lines changed: 121 additions & 201 deletions

File tree

example/pubspec.lock

Lines changed: 34 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
# Generated by pub
22
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
4-
args:
5-
dependency: transitive
6-
description:
7-
name: args
8-
sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6
9-
url: "https://pub.dev"
10-
source: hosted
11-
version: "2.6.0"
12-
asn1lib:
13-
dependency: transitive
14-
description:
15-
name: asn1lib
16-
sha256: "1c296cd268f486cabcc3930e9b93a8133169305f18d722916e675959a88f6d2c"
17-
url: "https://pub.dev"
18-
source: hosted
19-
version: "1.5.9"
204
async:
215
dependency: transitive
226
description:
@@ -45,26 +29,26 @@ packages:
4529
dependency: transitive
4630
description:
4731
name: characters
48-
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
32+
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
4933
url: "https://pub.dev"
5034
source: hosted
51-
version: "1.3.0"
35+
version: "1.4.1"
5236
clock:
5337
dependency: transitive
5438
description:
5539
name: clock
56-
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
40+
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
5741
url: "https://pub.dev"
5842
source: hosted
59-
version: "1.1.1"
43+
version: "1.1.2"
6044
collection:
6145
dependency: "direct main"
6246
description:
6347
name: collection
64-
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
48+
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
6549
url: "https://pub.dev"
6650
source: hosted
67-
version: "1.19.0"
51+
version: "1.19.1"
6852
convert:
6953
dependency: transitive
7054
description:
@@ -97,14 +81,6 @@ packages:
9781
url: "https://pub.dev"
9882
source: hosted
9983
version: "2.1.1"
100-
encrypt:
101-
dependency: transitive
102-
description:
103-
name: encrypt
104-
sha256: "62d9aa4670cc2a8798bab89b39fc71b6dfbacf615de6cf5001fb39f7e4a996a2"
105-
url: "https://pub.dev"
106-
source: hosted
107-
version: "5.0.3"
10884
equatable:
10985
dependency: "direct main"
11086
description:
@@ -117,10 +93,10 @@ packages:
11793
dependency: transitive
11894
description:
11995
name: fake_async
120-
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
96+
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
12197
url: "https://pub.dev"
12298
source: hosted
123-
version: "1.3.1"
99+
version: "1.3.3"
124100
ffi:
125101
dependency: transitive
126102
description:
@@ -143,7 +119,7 @@ packages:
143119
path: ".."
144120
relative: true
145121
source: path
146-
version: "6.0.0"
122+
version: "6.1.0"
147123
flutter:
148124
dependency: "direct main"
149125
description: flutter
@@ -231,14 +207,6 @@ packages:
231207
url: "https://pub.dev"
232208
source: hosted
233209
version: "4.1.2"
234-
js:
235-
dependency: transitive
236-
description:
237-
name: js
238-
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
239-
url: "https://pub.dev"
240-
source: hosted
241-
version: "0.7.1"
242210
json_annotation:
243211
dependency: transitive
244212
description:
@@ -251,26 +219,26 @@ packages:
251219
dependency: transitive
252220
description:
253221
name: leak_tracker
254-
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
222+
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
255223
url: "https://pub.dev"
256224
source: hosted
257-
version: "10.0.7"
225+
version: "11.0.2"
258226
leak_tracker_flutter_testing:
259227
dependency: transitive
260228
description:
261229
name: leak_tracker_flutter_testing
262-
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
230+
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
263231
url: "https://pub.dev"
264232
source: hosted
265-
version: "3.0.8"
233+
version: "3.0.10"
266234
leak_tracker_testing:
267235
dependency: transitive
268236
description:
269237
name: leak_tracker_testing
270-
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
238+
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
271239
url: "https://pub.dev"
272240
source: hosted
273-
version: "3.0.1"
241+
version: "3.0.2"
274242
lints:
275243
dependency: transitive
276244
description:
@@ -283,26 +251,26 @@ packages:
283251
dependency: transitive
284252
description:
285253
name: matcher
286-
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
254+
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
287255
url: "https://pub.dev"
288256
source: hosted
289-
version: "0.12.16+1"
257+
version: "0.12.19"
290258
material_color_utilities:
291259
dependency: transitive
292260
description:
293261
name: material_color_utilities
294-
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
262+
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
295263
url: "https://pub.dev"
296264
source: hosted
297-
version: "0.11.1"
265+
version: "0.13.0"
298266
meta:
299267
dependency: transitive
300268
description:
301269
name: meta
302-
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
270+
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
303271
url: "https://pub.dev"
304272
source: hosted
305-
version: "1.15.0"
273+
version: "1.17.0"
306274
nested:
307275
dependency: transitive
308276
description:
@@ -315,10 +283,10 @@ packages:
315283
dependency: transitive
316284
description:
317285
name: path
318-
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
286+
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
319287
url: "https://pub.dev"
320288
source: hosted
321-
version: "1.9.0"
289+
version: "1.9.1"
322290
path_drawing:
323291
dependency: transitive
324292
description:
@@ -411,10 +379,10 @@ packages:
411379
dependency: transitive
412380
description:
413381
name: pointycastle
414-
sha256: "4be0097fcf3fd3e8449e53730c631200ebc7b88016acecab2b0da2f0149222fe"
382+
sha256: "92aa3841d083cc4b0f4709b5c74fd6409a3e6ba833ffc7dc6a8fee096366acf5"
415383
url: "https://pub.dev"
416384
source: hosted
417-
version: "3.9.1"
385+
version: "4.0.0"
418386
provider:
419387
dependency: transitive
420388
description:
@@ -504,18 +472,18 @@ packages:
504472
dependency: transitive
505473
description:
506474
name: stack_trace
507-
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
475+
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
508476
url: "https://pub.dev"
509477
source: hosted
510-
version: "1.12.0"
478+
version: "1.12.1"
511479
stream_channel:
512480
dependency: transitive
513481
description:
514482
name: stream_channel
515-
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
483+
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
516484
url: "https://pub.dev"
517485
source: hosted
518-
version: "2.1.2"
486+
version: "2.1.4"
519487
string_scanner:
520488
dependency: transitive
521489
description:
@@ -536,10 +504,10 @@ packages:
536504
dependency: transitive
537505
description:
538506
name: test_api
539-
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
507+
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
540508
url: "https://pub.dev"
541509
source: hosted
542-
version: "0.7.3"
510+
version: "0.7.10"
543511
typed_data:
544512
dependency: transitive
545513
description:
@@ -552,10 +520,10 @@ packages:
552520
dependency: transitive
553521
description:
554522
name: vector_math
555-
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
523+
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
556524
url: "https://pub.dev"
557525
source: hosted
558-
version: "2.1.4"
526+
version: "2.2.0"
559527
vm_service:
560528
dependency: transitive
561529
description:
@@ -589,5 +557,5 @@ packages:
589557
source: hosted
590558
version: "6.5.0"
591559
sdks:
592-
dart: ">=3.6.0 <4.0.0"
560+
dart: ">=3.9.0-0 <4.0.0"
593561
flutter: ">=3.24.0"

lib/src/core/tools/security.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ import 'dart:math';
33
import 'dart:typed_data';
44

55
import 'package:crypto/crypto.dart';
6-
import 'package:encrypt/encrypt.dart';
6+
import 'package:pointycastle/export.dart';
77

88
class StorageSecurity {
99
final _random = Random.secure();
1010
final String? password;
1111
late Uint8List _encryptedPassword;
12-
late Encrypter _enc;
1312
StorageSecurity(this.password) {
1413
_encryptedPassword = _generateEncryptPassword(password!);
15-
_enc = Encrypter(Salsa20(Key(_encryptedPassword)));
1614
}
1715
Uint8List _generateEncryptPassword(String password) {
1816
var blob = Uint8List.fromList(md5.convert(utf8.encode(password)).bytes);
@@ -25,22 +23,29 @@ class StorageSecurity {
2523
List<int>.generate(length, (i) => _random.nextInt(256)));
2624
}
2725

26+
Uint8List _process(Uint8List input, Uint8List iv) {
27+
final engine = Salsa20Engine()
28+
..init(true, ParametersWithIV(KeyParameter(_encryptedPassword), iv));
29+
return engine.process(input);
30+
}
31+
2832
String encrypt(String value) {
2933
final iv = _randBytes(8);
3034
final ivEncoded = base64.encode(iv);
3135
assert(ivEncoded.length == 12);
32-
final encoded = _enc.encrypt(json.encode(value), iv: IV(iv)).base64;
36+
final input = Uint8List.fromList(utf8.encode(json.encode(value)));
37+
final encoded = base64.encode(_process(input, iv));
3338
return '$ivEncoded$encoded';
3439
}
3540

3641
String? decrypt(String value) {
3742
assert(value.length >= 12);
38-
final iv = base64.decode(value.substring(0, 12));
43+
final iv = Uint8List.fromList(base64.decode(value.substring(0, 12)));
3944

40-
// Extract the real input
4145
value = value.substring(12);
4246

43-
// Decode the input
44-
return json.decode(_enc.decrypt64(value, iv: IV(iv))) as String?;
47+
final cipher = base64.decode(value);
48+
final plain = _process(Uint8List.fromList(cipher), iv);
49+
return json.decode(utf8.decode(plain)) as String?;
4550
}
4651
}

0 commit comments

Comments
 (0)