Untitled

 avatar
faisalsalameh
dart
a year ago
975 B
2
Indexable
Future encrypter({String? storageKey, String? pss}) async {
    FlutterSecureStorage storage = const FlutterSecureStorage();
    final plainText = pss!;
    final key = encrypt.Key.fromLength(128);
    final iv = encrypt.IV.fromLength(8);
    final encrypter = encrypt.Encrypter(encrypt.Salsa20(key));

    final encrypted = encrypter.encrypt(plainText, iv: iv);
    await storage.write(key: storageKey!, value: encrypted.base64);
  }

  Future<String>? decrypter({String? storageKey}) async {
    FlutterSecureStorage storage = const FlutterSecureStorage();
    String? decrypted = await storage.read(key: storageKey!);
    String mallPass = '';
    print(decrypted);
    final key = encrypt.Key.fromLength(128);
    final iv = encrypt.IV.fromLength(8);
    final encrypter = encrypt.Encrypter(encrypt.Salsa20(key));
    if (decrypted != null) {
      mallPass = encrypter.decrypt64(decrypted, iv: iv);
      print(mallPass);
      return mallPass;
    }

    return '';
  }
Leave a Comment