react-native-crypto-js icon indicating copy to clipboard operation
react-native-crypto-js copied to clipboard

Decryption using CryptoJS.AES.decrypt results empty String

Open nikitpanchal opened this issue 5 years ago • 19 comments

var scanIO = "encrpytedstring"; above scanIO variable is generated from web Crypto JS library and below i'm decrypting in React-native let scannedGuid = CryptoJS.enc.Utf8.stringify(CryptoJS.AES.decrypt(scanIO, 'seckey'))

above code Returns empty string, but when i try same thing on Web version CryptoJS libraries using Web tools it gives me required output. Could you help is it because the conflict of Web and react-native version ?

React native version : 0.59.1

nikitpanchal avatar Sep 06 '19 06:09 nikitpanchal

@nikitpanchal Thank you for reporting issues, can you please share a sample code? I will check and fix it as soon as possible.

imchintan avatar Sep 10 '19 11:09 imchintan

same here.

in simulator it's working but when I deploy a debug .apk returns empty string

const bytes = CryptoJS.AES.decrypt(data, secret); const originalText = bytes.toString(CryptoJS.enc.Utf8); return originalText

also React native version: 0.59.1

Markuson avatar Dec 02 '19 19:12 Markuson

The same for RN 0.61.4

petrNikolaev1 avatar Dec 14 '19 18:12 petrNikolaev1

Hi is there any solution to this yet?

I have confirmed with RN 0.61.4, the AES decrypt will work fine while the scheme of the app is in develop, but upon making a proper release build it will return an empty string.

Metroxe avatar Mar 07 '20 03:03 Metroxe

I could not find a solution, I am not using the NodeJS CryptoJs library for this.

Metroxe avatar Mar 09 '20 19:03 Metroxe

@Metroxe Could you please send me more information or put your sample code here that I check?

imchintan avatar Mar 13 '20 11:03 imchintan

same here

I try use this lib between two differents devices, but decrypt returns empty string if I try decrypt before make a encrypt.

In my case, one device encrypt the password and send for the server.. when I try do login in another device.. the decrypt returns empty key.

ghost avatar Apr 01 '20 19:04 ghost

decrypt not working in APK (android) return empty string
let str = "mystring"; let bytes = CryptoJS.AES.decrypt(str, CONST.SHARE_KEY); let originalText = bytes.toString(CryptoJS.enc.Utf8); console.log("originalText 2", ''"); <------ output

react-native : 0.61

girish54321 avatar Apr 25 '20 13:04 girish54321

use "crypto-js": "3.3.0", not react native CryptoJS only v 3.3.0 will work in APK add "crypto-js": "3.3.0" in your package.json

girish54321 avatar May 01 '20 07:05 girish54321

Same problem here.

I changed to "crypto-js": "3.1.9-1" and works fine.

mechanizzed avatar May 15 '20 18:05 mechanizzed

I am facing the same issue that in debug mode everything works fine but in release mode of android it returns empty string.

export const decryptEncryptedKeyFromServer = async (encryptedKey) => {
    let bytes = await CryptoJS.AES.decrypt(encryptedKey, Config?.SECRET_KEY);
    let decryptedKey = await bytes.toString(CryptoJS.enc.Utf8);
    return decryptedKey;
}

where encryptedKey is from server and Config?.SECRET_KEY is secret used for encryption

RishavKumar-3796 avatar Sep 26 '20 19:09 RishavKumar-3796

is yet?

I have confirmed with RN 0.61.4, the AES decrypt will work fine while the scheme of the app is in develop, but upon making a proper release build it will return an empty string.

Fixed? Any solutions?

RishavKumar-3796 avatar Sep 26 '20 19:09 RishavKumar-3796

Same problem here.

I changed to "crypto-js": "3.1.9-1" and works fine.

Thanks it works

priyak-sdei avatar Jun 09 '21 13:06 priyak-sdei

anyone figured out this one . its returning a null. heres the code for decrypting ..

router.decryptData = function (ciphertext) {

const bytes = CryptoJS.AES.decrypt(ciphertext, config.ENCRYPTION_SALT);

try { return JSON.parse(bytes.toString(CryptoJS.enc.Utf8)) }

catch (err) { return null }

}

SVBellamkonda avatar Mar 18 '22 07:03 SVBellamkonda

any other solutions than installing the previous version of this package?

IhsenBen avatar Apr 04 '22 13:04 IhsenBen

same here

I try use this lib between two differents devices, but decrypt returns empty string if I try decrypt before make a encrypt.

In my case, one device encrypt the password and send for the server.. when I try do login in another device.. the decrypt returns empty key.

Yeah me too. One microservice was encrypting and then delegating the decryption to other downstream services. but it wouldn't work if the encryption was done on different machine. it works however if am using the same machine. the weird part is that using docker doesn't seem to have any impact.

avici1 avatar Jul 19 '22 15:07 avici1

Has this been resolved? I am having the same issue with CryptoJS 4.1.1. Encrypting on one machine/app and decrypting on another returns an empty string upon decryption.

torressam333 avatar Jan 26 '23 17:01 torressam333

anyone ever find a solution for this? Im on 4.1.1.

blustreeky23 avatar Mar 07 '23 20:03 blustreeky23

@blustreeky23 for my case I was passing values as encrypted from the process.env.secrety_key and for some reason that value was null prior to being passed to the encrypt() method. Not a solid solution but worth double checking that the value being encrypted isn't an empty string| null to begin with.

torressam333 avatar Mar 07 '23 20:03 torressam333