imchintan / react-native-crypto-js

CryptoJS is a growing collection of standard and secure cryptographic algorithms implemented in JavaScript using best practices and patterns. They are fast, and they have a consistent and simple interface.
MIT License
40 stars 22 forks source link

Decryption using CryptoJS.AES.decrypt results empty String #6

Open nikitpanchal opened 5 years ago

nikitpanchal commented 5 years ago

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

imchintan commented 5 years ago

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

Markuson commented 4 years ago

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

petrNikolaev1 commented 4 years ago

The same for RN 0.61.4

Metroxe commented 4 years ago

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 commented 4 years ago

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

imchintan commented 4 years ago

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

ghost commented 4 years ago

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.

girish54321 commented 4 years ago

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 commented 4 years ago

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

mechanizzed commented 4 years ago

Same problem here.

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

RishavKumar-3796 commented 4 years ago

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 commented 4 years ago

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?

priyak-sdei commented 3 years ago

Same problem here.

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

Thanks it works

SVBellamkonda commented 2 years ago

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 }

}

IhsenBen commented 2 years ago

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

avici1 commented 2 years ago

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.

torressam333 commented 1 year ago

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.

blustreeky23 commented 1 year ago

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

torressam333 commented 1 year ago

@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.