leocavalcante / encrypt

🔒 A set of high-level APIs over PointyCastle for two-way cryptography.
BSD 3-Clause "New" or "Revised" License
348 stars 141 forks source link

how to handle spaces ? #284

Open AdrienLemaire opened 2 years ago

AdrienLemaire commented 2 years ago

Generating keys as follow

var key = encrypt.Key.fromUtf8(aesKey);
var iv = encrypt.IV.fromLength(16);
final encrypter = encrypt.Encrypter(encrypt.AES(key, padding: null));
final code = encrypter
    .encrypt(myString, iv: iv)
    .base64;

I notice that regularly, a code will be generated with a space in it, eg MjvmDDtmCLTg AxL1GrBVK4Ns1vKtm/qtwARv5fyWBPHWg== In that case, the following code breaks:

encrypt.Encrypted.fromBase64(code)

traceback

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following FormatException was thrown building Builder(dirty):
Invalid character (at character 13)
MjvmDDtmCLTg AxL1GrBVK4Ns1vKtm/qtwARv5fyWBPHWg==
            ^

What is the proper resolution in this case ?

AdrienLemaire commented 2 years ago

@leocavalcante hi Leo, this error occurs quite frequently for me, so I'm assuming this is not a library bug but something I did wrong ? Do you have any idea what could cause this "Invalid character" error and how I could resolve it ?

AdrienLemaire commented 2 years ago

@leocavalcante is the project not maintained anymore ?