How To Encrypt Data Using AES With CBC Mode And PCS5Padding Status In Dart?

- 1 answer

I need to encrypt some data with AES and CBC mode, PCS5Padding status in dart. I searched but I haven't found any package in with PCS5Padding status. I tried the below code but encryption here with PCS7Padding not PCS5Padding using encrypt package.

  List plainTranData = [JSON data];
  final iv = IV.fromUtf8(vector value);
  final key = Key.fromUtf8(key);
  final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
  final encrypted =  encrypter.encrypt(plainTranData.toString(), iv: iv);
  print(encrypted.base16);  // <-- encrypted data in Hex/base16


As Richard Heap notes in the comments, there's no practical difference between them. PKCS5 is really just a special case of PKCS7. In many cases, implementations that call themselves "PKCS5" actually implement PKCS7. (This shouldn't be taken to mean that the "5" and "7" here are version numbers. They're not. They refer to specific Public Key Cryptography Standards documents. Two somewhat unrelated documents include the same basic padding strategy. There is no document devoted just to this padding strategy.)

For more details on this, see What is the difference between PKCS#5 padding and PKCS#7 padding on