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.