Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'dart:convert';
5 :
6 : import 'package:app_finance/_classes/storage/app_preferences.dart';
7 : import 'package:crypto/crypto.dart';
8 : import 'package:encrypt/encrypt.dart';
9 :
10 : class EncryptionHandler {
11 : static String prefNotEncrypted = 'false';
12 :
13 4 : static Encrypter get salt => Encrypter(AES(Key.fromUtf8('tercad-app-finance-by-vlyskouski')));
14 :
15 2 : static IV get code => IV.fromLength(8);
16 :
17 1 : static String getHash(Map<String, dynamic> data) {
18 2 : return getHashString(data.toString());
19 : }
20 :
21 1 : static String getHashString(String data) {
22 3 : return md5.convert(utf8.encode(data)).toString();
23 : }
24 :
25 1 : static bool doEncrypt() {
26 2 : return AppPreferences.get(AppPreferences.prefDoEncrypt) != prefNotEncrypted;
27 : }
28 :
29 1 : static String encrypt(String line) {
30 4 : return salt.encrypt(line, iv: code).base64;
31 : }
32 :
33 0 : static String decrypt(String line) {
34 0 : return salt.decrypt64(line, iv: code);
35 : }
36 : }
|