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

Issue when encrypt #47

Open
celciusjj opened this issue Jan 15, 2021 · 5 comments
Open

Issue when encrypt #47

celciusjj opened this issue Jan 15, 2021 · 5 comments

Comments

@celciusjj
Copy link

Error: exception decoding Hex string: invalid characters encountered in Hex string

@arunahuja94
Copy link

Getting same error, have you found any solutions?

@iJimmyWei
Copy link

iJimmyWei commented Mar 10, 2021

I also had this issue, my key + IV used had special characters in, i.e an =

If you just a normal alphanumeric key + IV, i.e say
591825e3a4f2c9b8f73eb963c77ad160d4802ad7aadc179b066275bcb9d9cfd2 then it seems to work.. seems rather counter intuitive, particularly if you're generating random keys.
const cipherText = await Aes.encrypt(data, "591825e3a4f2c9b8f73eb963c77ad160d4802ad7aadc179b066275bcb9d9cfd2", "0123456789abcdef0123456789abcde");

const randomKey = await Aes.randomKey(32);
const randomIv = await Aes.randomKey(16);

const cipherText = await Aes.encrypt(data, randomKey, randomIv);

@joan17cast
Copy link

Im getting the same error.

i let my code here, if you found any solution please let me know.

function buildSign(data, config) {
  try {
    encryptData(data.toString(), config)
    .then(({ cipher, iv }) => {
        console.log('Encrypted:', cipher)

        Aes.hmac256(cipher, config).then(hash => {
            console.log('HMAC', hash)
        })
    })
    .catch(error => {
        console.log(error)
    })

  } catch (e) {
    console.error(e)
  }
  //return crypto.createHmac('sha256', config.API_SECRET).update(data).digest('hex');
}

image

Thank you so much!
Sorry for my english. 😋

@MedRaid
Copy link

MedRaid commented Mar 17, 2022

same issue, but apparently you should try to generate a random key rather then passing your own key, that was the issue for me i added my own key that had apparently invalid caracters, use this instead

const handleSubmitForm = async (values, hash) => {
const randomIv = await Aes.randomKey(16);

try {
  console.log('Key:', randomIv);
  encryptData('k]]xM2uPFpkLWPBas&}46^FN.H9738', randomIv)
    .then(({cipher, iv}) => {
      console.log('Encrypted:', cipher);
    })
    .catch(error => {
      console.log('error', error);
    });
} catch (e) {
  console.error(e);
}

};

@CyberCyclone
Copy link

same issue, but apparently you should try to generate a random key rather then passing your own key, that was the issue for me i added my own key that had apparently invalid caracters, use this instead

const handleSubmitForm = async (values, hash) => { const randomIv = await Aes.randomKey(16);

try {
  console.log('Key:', randomIv);
  encryptData('k]]xM2uPFpkLWPBas&}46^FN.H9738', randomIv)
    .then(({cipher, iv}) => {
      console.log('Encrypted:', cipher);
    })
    .catch(error => {
      console.log('error', error);
    });
} catch (e) {
  console.error(e);
}

};

As far as I can see, this means we can't use this package as a drop in replacement for nodejs version of crypto or use it alongside nodejs. E.g, if a developer needs to use hmac256 as part of a HTTP header authorization request, it will fail because the key used on the server will be different to the one used with this package, and therefore produce two very different hashes.

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

6 participants