AKushWarrior / steel_crypt

A collection of high-level API's exposing PointyCastle to perform hashing and encrypting in popular/secure algorithms.
https://pub.dev/packages/steel_crypt
Mozilla Public License 2.0
40 stars 10 forks source link

aes how to set 'zeropadding' in 'cbc' mode? #25

Closed lumia1999 closed 4 years ago

lumia1999 commented 4 years ago

aes how to set 'zeropadding' in 'cbc' mode?

alexgoussev commented 4 years ago

I'd suppose you need to set third parameter as 'none' in AesCrypt() constructor. (it's from sources).

AKushWarrior commented 4 years ago

DON'T use @alexgoussev's answer. The source code is a little ambiguous, but 'none' is not a valid option and will lead to unpredictable behavior.

Refer to my answer in #6. It's the same issue (with ECB instead of CBC), and provides a nice explanation of why padding is necessary.

The summary version of it:

String data = 'DataGoesHereLike'; //some data
assert(data.codeunits.length % 16 == 0)

If that assert statement evaluates to 'true', it doesn't matter what you put in the padding parameter: the encrypted data will be the same regardless.

AKushWarrior commented 4 years ago

Lemme know if you have more issues