Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBC encrypt and decrypt is wrong on output #106

Closed
RaresAil opened this issue Jul 9, 2021 · 3 comments
Closed

CBC encrypt and decrypt is wrong on output #106

RaresAil opened this issue Jul 9, 2021 · 3 comments

Comments

@RaresAil
Copy link

RaresAil commented Jul 9, 2021

  public encrypt(data: string) {
    return Buffer.from(
      this.CBC.encrypt(padding.pkcs7.pad(utils.utf8.toBytes(data)))
    ).toString('base64');
  }

  public decrypt(data: string) {
    return Buffer.from(
      padding.pkcs7.strip(this.CBC.decrypt(Buffer.from(data, 'base64')))
    ).toString('utf-8');
  }

As a test i did a encrypt and then a decrypt and the output is like:

Expected input

'{"method":"login_device","params":{...

Real output:

'��mWL�u�i\x14��-�pK_device","params":{

The rest of the string json (at ....) is good, only the first 16 characters are not

@brandtiwari007
Copy link

Hi @RaresAil have you got solution for this

@RaresAil
Copy link
Author

@webdevelopland
Copy link

16 characters is one block. Probably it's related to iv. I guess you used different iv for encryption and decryption.

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

No branches or pull requests

3 participants