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

Unable to pass in WordArray as key to AES.encrypt #49

Open
raghavsethi opened this issue Jul 31, 2024 · 0 comments
Open

Unable to pass in WordArray as key to AES.encrypt #49

raghavsethi opened this issue Jul 31, 2024 · 0 comments

Comments

@raghavsethi
Copy link

raghavsethi commented Jul 31, 2024

Hey folks, I'm a bit confused by why this doesn't work - is the AES 256 implementation only designed to work with string keys? Switching the key out to be a string in the following code causes the test to pass:

Relevant code:

import { WordArray } from "crypto-es/lib/core";
import CryptoES from "crypto-es";

const key = WordArray.random(32);
const plaintext = WordArray.random(32);
const cipherParams = CryptoES.AES.encrypt(plaintext, key);
const decrypted = CryptoES.AES.decrypt(cipherParams, key);
expect(decrypted.toString(CryptoES.enc.Hex)).toEqual(
	plaintext.toString(CryptoES.enc.Hex),
);

Expected output: test pass

Actual output: (fails at encryption step)

    TypeError: Cannot read properties of undefined (reading '0')
      at _class.xorBlock (node_modules/crypto-es/lib/cipher-core.js:280:32)
      at _class.call [as processBlock] (node_modules/crypto-es/lib/cipher-core.js:313:14)
      at AESAlgo.processBlock [as _doProcessBlock] (node_modules/crypto-es/lib/cipher-core.js:463:16)
      at AESAlgo._doProcessBlock [as _process] (node_modules/crypto-es/lib/core.js:530:14)
      at AESAlgo._process [as _doFinalize] (node_modules/crypto-es/lib/cipher-core.js:478:35)
      at AESAlgo._doFinalize [as finalize] (node_modules/crypto-es/lib/cipher-core.js:175:37)
      at Function.finalize [as encrypt] (node_modules/crypto-es/lib/cipher-core.js:651:34)
      at Object.encrypt (node_modules/crypto-es/lib/cipher-core.js:110:42)

AES 256 should accept a 256-bit (32-byte) key, so I imagine something else is going wrong here.

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

1 participant