2

I need an easy solution for encrypt a string in AES from my React Native app, send to the server and the decrypt from there with Java. I found some solutions but I am not able to make it works... Thanks a lot!

2
  • 1
    Easy solution: Use HTTPS. Commented Jul 8, 2021 at 14:52
  • 1
    I found some solutions but I am not able to make it works... please provide more details (e. g. code in React and in Java), otherwise we're guessing. Regardless that - are you trying something where https in not enough? Commented Jul 15, 2021 at 15:18

1 Answer 1

1

For the Javascript/React Native side I've used crypto-js before which should just be a couple lines of code to implement.

npm install crypto-js

Then in your code

import AES from 'crypto-js/aes'

const stringToEncrypt = 'my string';
const secretKey = 'secret key 123';
const encryptedString = AES.encrypt(stringToEncrypt, secretKey).toString();

Then you can send encryptedString to your server, prefereably via https using something like Axios or Fetch

Sign up to request clarification or add additional context in comments.

3 Comments

Thx, almost all the examples I found with AES are using a secret key with salt and an Initialization vector. I try to replicate the same then in Java, but the encrypted strings I get are different. In your example, do you know how to read that in Java?
On reflection yes you will need a key to encrypt via AES. You could store this securely on the server and in your React Native code using environment variables to keep it secure. I have updated my answer accordingly. My Java isn't great so I would suggest looking up decryption using Cypher (import javax.crypto.Cipher) docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html
In my case secret key is placed in a keystore file, how can i read and access key from it in order to use in react native to encrypt my plain text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.