Input data must be multiple of cipher block size in AES CTR mode
This is a problem in Dart's encrypt package. It cannot handle something encrypted using AES CTR mode if it isn't a multiple of the block size. This package is wrapper for Pointy Castle, which I was able to use successfully to decrypt a string encrypted using AES CTR mode. Here's the code:
import 'package:encrypt/encrypt.dart' as encrypt;import 'package:pointycastle/export.dart' as pc;String decrypt(String cipher, Uint8List key, Uint8List iv) { final encryptedText = encrypt.Encrypted.fromBase16(cipher); final ctr = pc.CTRStreamCipher(pc.AESFastEngine()) ..init(false, pc.ParametersWithIV(pc.KeyParameter(key.bytes), iv.bytes)); Uint8List decrypted = ctr.process(encryptedText.bytes); print(String.fromCharCodes(decrypted)); return String.fromCharCodes(decrypted);}
cipher
is a hexadecimal string. encrypt's package is still useful because it provides utilities for converting a hexadecimal string to a Uint8List