Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AES128 produces result longer than 16 bytes in Flutter Encrypt package #286

Open
adnan-creator opened this issue Oct 31, 2022 · 0 comments

Comments

@adnan-creator
Copy link

I am working on a flutter project where we need to encrypt a plaintext that is given in hex with a key that is also given in hex. We're using a package called encrypt which only accepts plaintext as String and most of the online AES tools also assume the plaintext to be String. So we tried converting the hex to String but to no avail, we always get the result longer than 16 bytes. This only seems to be the result with our particular String (that has special characters). So other Strings the length of the ciphertext is as expected.

KEY = B0A42687AA50A67A6DCEB68EA59A1332 (16 Bytes)
Plaintext = A0A1A2A3A4A5A6A7B1B2B3B4B5B6B7B0 (16 Bytes)
Expected Ciphertext = D704CE5AAE286511A691AF8EF7D31FE1 (16 Bytes)

What we have tried so far and the results:

void main() {
  final plainText = 'A0A1A2A3A4A5A6A7B1B2B3B4B5B6B7B0' //Original Hex treated as String;
  final key = Key.fromBase16('0A42687AA50A67A6DCEB68EA59A1332');
  final iv = IV.fromLength(16);

  final encrypter = Encrypter(AES(key, mode: AESMode.ebc, padding: null));

  final encrypted = encrypter.encrypt(plainText, iv: iv);
  final decrypted = encrypter.decrypt(encrypted, iv: iv);

  print(encrypted.base16); // 477eobf5f216745a7b1daf703218861b2c26ba77843429adc8928a164CCCC435
}
void main() {
  final plainText = ' ¡¢£¤¥¦§±²³´µ¶·°' //Hex to equivalent String;
  final key = Key.fromBase16('0A42687AA50A67A6DCEB68EA59A1332');
  final iv = IV.fromLength(16);

  final encrypter = Encrypter(AES(key, mode: AESMode.ebc, padding: null));

  final encrypted = encrypter.encrypt(plainText, iv: iv);
  final decrypted = encrypter.decrypt(encrypted, iv: iv);

  print(encrypted.base16); // 268ceb0611e696ab9eeb4b87d51c60eedfd54a8755c5df5b3f657ee2b93936
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant