13

In my Android project, I want to keep my web service address unknown. I store the link as follows:

private final String SERVICE_LINK = "mywebservicelink..."

But since I saw that APK's can be decompiled, I wonder if this link can be known.

How can I store it securely?

Thanks.

Fadils
  • 1,508
  • 16
  • 21
Kerem
  • 1,494
  • 2
  • 16
  • 27
  • Don't assume you can get a secure solution. Everything can be recovered by reverse engineering. Some approaches may require some more work than others, but nothing is really secure. – Henry Oct 13 '15 at 08:57
  • 1
    better user pro-guard to encrypt ur source code. – Nandakishore Shetty Oct 13 '15 at 09:37

3 Answers3

6

You can set sensitive string in your gradle.properties

https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_properties_and_system_properties

For example:

in your gradle.properties (usually located in your root project), you can define:

SERVICE_LINK = "mywebservicelink"

Then in your application's build.gradle

android {
   ...
   defaultConfig {
       resValue "string", "service_link", SERVICE_LINK
   }
   ...
}

Then, this service link will be ready in your resource as R.string.service_link. That is, you can simply get the value by doing:

getString(R.string.service_link);

EDIT 1:

If you're asking about how to hide your strings in your APK, then you can use ProGuard. However, be advised. Whatever you put into your source code, there's no 100% guarantee that it cannot be reverse-engineered. ProGuard will obfuscate your code, which will make reverse-engineering harder significantly.

For more information, this thread is awesome: How to avoid reverse engineering of an APK file?

Community
  • 1
  • 1
Fadils
  • 1,508
  • 16
  • 21
2

You can assign value of SERVICE_LINK variable after doing some operations, instead of assigning directly. For example using string operations with a few meaningless strings, getting characters or substrings from some specific positions, getting some characters from ASCII code obtained by some arithmetic operations etc. may be helpful for the purpose.

This provides a complexity so that third party people don't find your constant value easily. They may think it's a dynamic value varying on run time, or something unrelated. But if it was in " " directly, it would be found easily.

Safa Kadir
  • 475
  • 1
  • 5
  • 18
0

As a rule of thumb, no network address can be hidden.

Anyone that is searching for webservices, addresses or related can monitor their own network, and capture the packages.

The domain or IP of host will always be in plain sight.

Bonatti
  • 2,778
  • 5
  • 23
  • 42