Skip to content

Instantly share code, notes, and snippets.

@ctkqiang
Last active June 12, 2021 05:53
Show Gist options
  • Save ctkqiang/eaefa0e2283e1363518cd8e1b77ca175 to your computer and use it in GitHub Desktop.
Save ctkqiang/eaefa0e2283e1363518cd8e1b77ca175 to your computer and use it in GitHub Desktop.
import "package:encrypt/encrypt.dart";
import "dart:convert";
class _encryption {
static int theKeyLength = 32;
static int theLengthOfInitialisationVector = 16;
static var key = Key.fromLength(theKeyLength);
static var iv = IV.fromLength(theLengthOfInitialisationVector);
static var AESENCRYPTOR = Encrypter(AES(key));
// AES-Symmetric, padding: random
encrypt_string(String sendMessage) {
var encrypted = AESENCRYPTOR.encrypt(sendMessage, iv:iv);
String encryptedHashes = encrypted.base64;
decrypt_string(encrypted);
return encryptedHashes;
}
decrypt_string(var encrypted) {
var decrypted = AESENCRYPTOR.decrypt(encrypted, iv:iv);
String DecryptedHashes = decrypted;
return DecryptedHashes;
}
}
void main () {
_encryption test = new _encryption();
var a = test.encrypt_string("hahslkjdflkjsdflksjdflksjdfslkdfjsldkfjah");
List <int> b = utf8.encode(a);
print(a);
print(b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment