encrypt icon indicating copy to clipboard operation
encrypt copied to clipboard

how to handle spaces ?

Open AdrienLemaire opened this issue 1 year ago • 2 comments

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 avatar Oct 01 '22 09:10 AdrienLemaire

@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 avatar Oct 04 '22 12:10 AdrienLemaire

@leocavalcante is the project not maintained anymore ?

AdrienLemaire avatar Oct 14 '22 12:10 AdrienLemaire