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 4 : return md5.convert(utf8.encode(data.toString())).toString(); 19 : } 20 : 21 1 : static bool doEncrypt() { 22 2 : return AppPreferences.get(AppPreferences.prefDoEncrypt) != prefNotEncrypted; 23 : } 24 : 25 1 : static String encrypt(String line) { 26 4 : return salt.encrypt(line, iv: code).base64; 27 : } 28 : 29 0 : static String decrypt(String line) { 30 0 : return salt.decrypt64(line, iv: code); 31 : } 32 : }