Let's say i'm building a react-native app with firebase, which assumes having secret key in app. Is it possible for someone to steal the key? If so, then how do i protect it?
If you must have an API key or a secret to access some resource from your app, the most secure way to handle this would be to build an orchestration layer between your app and the resource.
To store the API keys, create a new file called . env in the root directory of the React application. You can now access the API key in any file in the React app using process.
We'll hide our sensitive information by storing it in the . env or dotenv file. It's a text config file that helps us control the constants across our projects. You can create one in your by simply creating a new file and calling it.
Overview. You can encrypt the realm database file on disk with AES-256 + SHA-2 by supplying a 64-byte encryption key when opening a realm. Realm transparently encrypts and decrypts data with standard AES-256 encryption using the first 256 bits of the given 512-bit encryption key.
There's no 100% secure way to store anything secret on the device because you have no control over access to the source. The only way to guarantee security of your keys is to never have them on the device in the first place.
Any solution you find will have a flaw, illustrated quite nicely by this article by Michael Ramirez
You need to strike a balance of how secure you really need those keys to be.
For example on Android we store some of our keys we care less about for Google and other APIs in a res/values/secrets.xml string file, which is not committed to version control. It's easy for someone to strings out_app.api
, but we've already decided to care less about securing those keys.
<resources>
<string name="google_api_key">OurApiKey</string>
</resources>
If you're working with ReactNative on Android & depending on the types of key you want to store, you could make use of the Android Keystore System using the Keystore API however I don't think this will work for storing Firebase keys.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With