Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

AES-CBC has defined blocks of 16, raises the error on data length to be multiple of block size only #141

Open
aahmadfarooq opened this issue Jan 13, 2018 · 2 comments

Comments

@aahmadfarooq
Copy link

Hi, I have been trying to use "asmCrypto.AES_CBC.encrypt" function with the a 256 bit key and a varying length of data (since data cannot be limited and will be varying depending on request)

I was getting below error alot of time while invoking this:
data length must be a multiple of the block size

And upon debug realized that the AES_Encrypt_finish function has a defined variable plen = 16 and raises the issue in code below:

else if ( len % 16 ) { throw new IllegalArgumentError("data length must be a multiple of the block size"); }

@jeromewagener
Copy link

Hello @aahmadfarooq

I am not sure if it helps but I had a similar issue with the same error and resolved it by enabling padding.
Both the AES-CBC encryption and decryption have the padding flag in their constructor.

  /**
   * @param {Uint8Array} key
   * @param {Uint8Array} [iv=null]
   * @param {boolean} [padding=true]
   * @param {Uint8Array} [heap]
   * @param {Uint8Array} [asm]
   */
  constructor(key, iv, padding, heap, asm) {
    super(key, iv, padding, heap, asm);
}

Kind regards,
Jérôme

@alippai
Copy link
Member

alippai commented Feb 7, 2018

Are you using padding? If not, you have process blocks of size N*16.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants