Skip to content

AES only working with small strings (Invalid padding value) #14

@besserwisser

Description

@besserwisser

Hello,

I am trying to use the AES encryption. Sadly I can only get very small strings encrypted. For example "life is easy" works fine. But "life is the nicest of nicest" throws an error:

"Error: PKCS#5:unpad: Invalid padding value. expected [170], found [0]"

This is my current code snippet:

    var keyString = "sdphuif3479fhweafgh89epfg89e4ghuhw";
    var key = Crypto.getCharset("utf-8").encode(keyString);
    var cipher:ICipher = Crypto.getCipher("simple-aes256", key);
    log( "Key: " + keyString);

    var testString = "life is the nicest of nicest";
    // var testString = "life is nice";
    var data = Crypto.getCharset("utf-8").encode(testString);
    cipher.encrypt(data);
    log("original string: " + testString);

    var stringEncrypted = Base64.encode(data);
    log("Encrypted: " + stringEncrypted);

    var byteArray = Base64.decode(stringEncrypted);
    cipher.decrypt(byteArray);
    var stringDecrypted = Crypto.getCharset("utf-8").decode(byteArray);
    log("Decrypted: " + stringDecrypted);

The error message occurs on all targets (e.g. android and html5).

BTW: What also confused me is that even the short string, which worked fine, can't be decrypted using this tool:
http://aesencryption.net/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions