Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Secure keys in Java file like API keys, etc from hackers

Tags:

java

android

I am building an Android app and I am worried about app security of API and other keys. So I need a method to secure them from hackers!

I have already tried to store these keys on Firebase but it is not a perfect method as it uses a lot of data on Firebase and took time to receive.

like image 857
Megamind Core Avatar asked Jul 28 '19 03:07

Megamind Core


1 Answers

A safe option would be saving the KEY API values inside the local.properties file.

Inside your app/build.gradle file add the reference to the API KEY:

android {
     ...

    defaultConfig {
        ...
        buildConfigField "String", "myAPI_KEY", "\"API_KEY_VALUE\"" 
        ...
    }
     ...

}

Inside the local.properties file add the entry that defines the value of the API KEY:

API_KEY_VALUE="AIzaSy..............."

then, build your project and you can get the value of the API KEY from the BuildConfig class, example:

 String myApiKey = BuildConfig.myAPI_KEY;
like image 107
Jorgesys Avatar answered Oct 11 '22 14:10

Jorgesys