Skip to content

Instantly share code, notes, and snippets.

@VB10
Last active June 5, 2021 19:22
Show Gist options
  • Save VB10/95d32434b5c93867826018b3f34ee02e to your computer and use it in GitHub Desktop.
Save VB10/95d32434b5c93867826018b3f34ee02e to your computer and use it in GitHub Desktop.
class EncrypData implements IEncrypData {
late final Key key;
late final IV iv;
final String _privateKey = 'privateKey';
final String _privateINV = 'privateINV';
EncrypData() {
key = Key.fromUtf8(dotenv.env[_privateKey] ?? '');
iv = IV.fromUtf8(utf8.decode((dotenv.env[_privateINV] ?? '').codeUnits));
}
@override
String crypteFile(String data) {
final encrypter = Encrypter(AES(key, padding: null));
final encrypted = encrypter.encrypt(data, iv: iv);
return encrypted.base64;
}
@override
String decryptFile(String data) {
final encrypter = Encrypter(AES(key, padding: null));
final decrypted = encrypter.decrypt(Encrypted.from64(data), iv: iv);
return decrypted;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment