react-native-aes
react-native-aes copied to clipboard
Issue when encrypt
Error: exception decoding Hex string: invalid characters encountered in Hex string
Getting same error, have you found any solutions?
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);
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');
}

Thank you so much! Sorry for my english. 😋
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);
}
};