Chat Fixes & User Chat Counter
parent
cecb2d59e9
commit
f6f801f9cf
@ -0,0 +1,188 @@
|
||||
// import 'dart:convert';
|
||||
//
|
||||
// import 'package:encrypt/encrypt.dart';
|
||||
// import 'package:crypto/crypto.dart';
|
||||
//
|
||||
// class Encryption {
|
||||
// static final Encryption instance = Encryption._();
|
||||
//
|
||||
// late IV _iv;
|
||||
// late Encrypter _encrypter;
|
||||
//
|
||||
// Encryption._() {
|
||||
// const mykey = 'PeShVmYp';
|
||||
// const myiv = 'j70IbWYn';
|
||||
// var keyUtf8 = utf8.encode(mykey);
|
||||
// var ivUtf8 = utf8.encode(myiv);
|
||||
// var key = sha256.convert(keyUtf8).toString().substring(0, 32);
|
||||
// var iv = sha256.convert(ivUtf8).toString().substring(0, 16);
|
||||
// _iv = IV.fromUtf8(iv);
|
||||
//
|
||||
// _encrypter = Encrypter(AES(Key.fromUtf8(key), mode: AESMode.cbc));
|
||||
// }
|
||||
//
|
||||
// String encrypt(String value) {
|
||||
// return _encrypter.encrypt(value, iv: _iv).base64;
|
||||
// }
|
||||
//
|
||||
// String decrypt(String base64value) {
|
||||
// var encrypted = Encrypted.fromBase64(base64value);
|
||||
// return _encrypter.decrypt(encrypted, iv: _iv);
|
||||
// }
|
||||
//
|
||||
// //
|
||||
// // void passEncrypt(String text, String pass) async {
|
||||
// // var salt = randomUint8List(8);
|
||||
// // var keyndIV = deriveKeyAndIV(pass, salt);
|
||||
// // var key = encrypt.Key(keyndIV.item1);
|
||||
// // var iv = encrypt.IV(keyndIV.item2);
|
||||
// // var encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7"));
|
||||
// // var encrypted = encrypter.encrypt(text, iv: iv);
|
||||
// // Uint8List encryptedBytesWithSalt = Uint8List.fromList(createUint8ListFromString("Salted__") + salt + encrypted.bytes);
|
||||
// // var resulttt = base64.encode(encryptedBytesWithSalt);
|
||||
// // print("Enc : " + resulttt);
|
||||
// //
|
||||
// // decryptAESCryptoJS(resulttt, pass);
|
||||
// // }
|
||||
// //
|
||||
// // Uint8List randomUint8List(int length) {
|
||||
// // assert(length > 0);
|
||||
// // var random = Random();
|
||||
// // var ret = Uint8List(length);
|
||||
// // for (var i = 0; i < length; i++) {
|
||||
// // ret[i] = random.nextInt(256);
|
||||
// // }
|
||||
// // return ret;
|
||||
// // }
|
||||
// //
|
||||
// // void decryptAESCryptoJS(String encrypted, String passphrase) {
|
||||
// // try {
|
||||
// // Uint8List encryptedBytesWithSalt = base64.decode(encrypted);
|
||||
// // Uint8List encryptedBytes = encryptedBytesWithSalt.sublist(16, encryptedBytesWithSalt.length);
|
||||
// // var salt = encryptedBytesWithSalt.sublist(8, 16);
|
||||
// // var keyndIV = deriveKeyAndIV(passphrase, salt);
|
||||
// // var key = encrypt.Key(keyndIV.item1);
|
||||
// // var iv = encrypt.IV(keyndIV.item2);
|
||||
// // var encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7"));
|
||||
// // var decrypted = encrypter.decrypt64(base64.encode(encryptedBytes), iv: iv);
|
||||
// // print("Dec : " + decrypted);
|
||||
// // // return decrypted;
|
||||
// // } catch (error) {
|
||||
// // throw error;
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // Future<void> enc(String input) async {
|
||||
// // var ekey = "PeShVmYpPeShVmYp";
|
||||
// // var eIV = "j70IbWYnj70IbWYn";
|
||||
// //
|
||||
// // var abc = Encryption.instance.encrypt(input);
|
||||
// // //
|
||||
// // // var inputByt = utf8.encode(input);
|
||||
// // // final encrypted = encrypter.encrypt(plainText);
|
||||
// // // final decrypted = encrypter.decrypt(encrypted);
|
||||
// // //
|
||||
// // // print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit
|
||||
// // // print(encrypted.base64); // R4PxiU3h8YoIRqVowBXm36ZcCeNeZ4s1OvVBTfFlZRdmohQqOpPQqD1YecJeZMAop/hZ4OxqgC1WtwvX/hP9mw==
|
||||
// // // ///
|
||||
// //
|
||||
// // var key = encrypt.Key.fromUtf8(ekey.substring(0, 8));
|
||||
// // var iv = encrypt.IV.fromLength(8);
|
||||
// // var encrypter = Encrypter(AES(key));
|
||||
// // var encrypted = encrypter.encrypt(input, iv: iv);
|
||||
// // var decrypted = encrypter.decrypt(encrypted, iv: iv);
|
||||
// // print("====== ORI ==========");
|
||||
// // print("e4PTDencHsiLJv0XcbT2I4tafb7dqJP9c72PEnhp1Uv6U2GZ/gODtA==");
|
||||
// // print("====== ENC ==========");
|
||||
// // print(encrypted.base64);
|
||||
// // print("====== DEC ==========");
|
||||
// // print(decrypted);
|
||||
// // print("====== B64 ==========");
|
||||
// // String bs64 = base64.encode(utf8.encode(input));
|
||||
// // print(bs64);
|
||||
// //
|
||||
// // // try {
|
||||
// // // var cipher = _cipher;
|
||||
// // // var secretBox = await cipher.encrypt(
|
||||
// // // iByt,
|
||||
// // // secretKey: SecretKeyData(eByt),
|
||||
// // // nonce: eIvByt,
|
||||
// // // );
|
||||
// // // print(utf8.decode(secretBox.cipherText));
|
||||
// // // } catch (error) {
|
||||
// // // print(error);
|
||||
// // // return;
|
||||
// // // }
|
||||
// // }
|
||||
// // ///Accepts encrypted data and decrypt it. Returns plain text
|
||||
// // String decryptWithAES(String key, Encrypted encryptedData) {
|
||||
// // var cipherKey = encrypt.Key.fromUtf8(key);
|
||||
// // var encryptService = Encrypter(AES(cipherKey, mode: AESMode.cbc,padding: null));
|
||||
// // var initVector = IV.fromUtf8(key.substring(0, 16));
|
||||
// // return encryptService.decrypt(encryptedData, iv: initVector);
|
||||
// // }
|
||||
// //
|
||||
// // ///Encrypts the given plainText using the key. Returns encrypted data
|
||||
// // Encrypted encryptWithAES(String key, String plainText) {
|
||||
// // var cipherKey = encrypt.Key.fromUtf8(key);
|
||||
// // var encryptService = Encrypter(AES(cipherKey, mode: AESMode.cbc,padding: null));
|
||||
// // var initVector = IV.fromUtf8("j70IbWYn");
|
||||
// // Encrypted encryptedData = encryptService.encrypt(plainText, iv: initVector);
|
||||
// // print(encryptedData.base64);
|
||||
// // return encryptedData;
|
||||
// // }
|
||||
// //
|
||||
// // Tuple2<Uint8List, Uint8List> deriveKeyAndIV(String passphrase, Uint8List salt) {
|
||||
// // var password = createUint8ListFromString(passphrase);
|
||||
// // Uint8List concatenatedHashes = Uint8List(0);
|
||||
// // Uint8List currentHash = Uint8List(0);
|
||||
// // bool enoughBytesForKey = false;
|
||||
// // Uint8List preHash = Uint8List(0);
|
||||
// //
|
||||
// // while (!enoughBytesForKey) {
|
||||
// // int preHashLength = currentHash.length + password.length + salt.length;
|
||||
// // if (currentHash.length > 0)
|
||||
// // preHash = Uint8List.fromList(currentHash + password + salt);
|
||||
// // else
|
||||
// // preHash = Uint8List.fromList(password + salt);
|
||||
// //
|
||||
// // currentHash = preHash;
|
||||
// // concatenatedHashes = Uint8List.fromList(concatenatedHashes + currentHash);
|
||||
// // if (concatenatedHashes.length >= 48) enoughBytesForKey = true;
|
||||
// // }
|
||||
// //
|
||||
// // var keyBtyes = concatenatedHashes.sublist(0, 32);
|
||||
// // var ivBtyes = concatenatedHashes.sublist(32, 48);
|
||||
// // return new Tuple2(keyBtyes, ivBtyes);
|
||||
// // }
|
||||
// //
|
||||
// // Uint8List createUint8ListFromString(String s) {
|
||||
// // var ret = new Uint8List(s.length);
|
||||
// // for (var i = 0; i < s.length; i++) {
|
||||
// // ret[i] = s.codeUnitAt(i);
|
||||
// // }
|
||||
// // return ret;
|
||||
// // }
|
||||
// //
|
||||
// // Uint8List genRandomWithNonZero(int seedLength) {
|
||||
// // var random = Random.secure();
|
||||
// // const int randomMax = 245;
|
||||
// // Uint8List uint8list = Uint8List(seedLength);
|
||||
// // for (int i = 0; i < seedLength; i++) {
|
||||
// // uint8list[i] = random.nextInt(randomMax) + 1;
|
||||
// // }
|
||||
// // return uint8list;
|
||||
// // }
|
||||
// //
|
||||
// //
|
||||
// //
|
||||
// // void test(String text, String kk) {
|
||||
// // Uint8List key = Uint8List.fromList(utf8.encode(kk));
|
||||
// // PaddedBlockCipher cipher = exp.PaddedBlockCipherImpl(exp.PKCS7Padding(), exp.ECBBlockCipher(exp.AESEngine()));
|
||||
// // cipher.init(true, PaddedBlockCipherParameters<CipherParameters, CipherParameters>(KeyParameter(key), null));
|
||||
// // var byte = Uint8List.fromList(utf8.encode(text));
|
||||
// // var data = cipher.process(byte);
|
||||
// // print(data);
|
||||
// // }
|
||||
//
|
||||
// }
|
Loading…
Reference in New Issue