I encrypt a string using Dart's encrypt package. The code I encrypted is below.
String encrypt(String kelime) {
final key = Key.fromUtf8('H4WtkvK4qyehIe2kjQfH7we1xIHFK67e'); //32 length
final iv = IV.fromUtf8('HgNRbGHbDSz9T0CC');
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted = encrypter.encrypt(kelime, iv: iv);
return encrypted.base64;
}
Then I decode the encrypted data with the same package and I get this error Input data length must be a multiple of cipher's block size. After some research, I learned that the encrypt package had trouble deciphering the AES encryption algorithm. I have learned that the encrypted word can be decrypted with the Pointycastle package. Code below
String decryptt(String cipher) {
final key = Key.fromUtf8('H4WtkvK4qyehIe2kjQfH7we1xIHFK67e');
final iv = IV.fromUtf8('HgNRbGHbDSz9T0CC');
final encryptedText = Encrypted.fromUtf8(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);
}
When I decrypt data encrypted with pointycastle I get an output like this.
có¥ÄÐÒË.å$[~?q{.. 9
The word I encrypt is
Hello
Packs of darts I use