Last active
June 5, 2021 19:22
-
-
Save VB10/95d32434b5c93867826018b3f34ee02e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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