Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28474

Issue in AES encryption for android - dev vs release build using react-native-crypto-js package

$
0
0
import CryptoJS from "react-native-crypto-js";

//encryption function used in react native code base

export const encryptValue = (text) => {

try {

        const key = 'J4f9eO8ayjjEtamRBxSSmsDqXBele1zl'
        const iv = CryptoJS.lib.WordArray.random(128 / 8)
        let encrypted = CryptoJS.AES.encrypt(
            text, key, {
                keySize: 16,
                iv: iv,
            });
        let v = { iv: iv.toString(), encryptedData: encrypted.toString() }
        return v
    } catch (error) {
        console.log('error - ', error)
    }
}

const crypto = require('crypto-js')

//decryption function used in server - node

export const decrypt = (data) => {


try {

        let key = "J4f9eO8ayjjEtamRBxSSmsDqXBele1zl"
        let decrypted = crypto.AES.decrypt(
            data.encryptedData, key, {
                keySize: 16,
                iv: data.iv
            }).toString(crypto.enc.Utf8)
        console.log('decrypted - ', decrypted)
        return decrypted.toString()
    } catch (err) {
        console.log('err', err)
    }

}

Above code encryption and decryption works fine for android debug build and server side code. However, Android build generated in release.. generates encrypted text, but does not decrypt at server.


Viewing all articles
Browse latest Browse all 28474

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>