现在我正在开发一个Android应用程序,我对此非常陌生。
我想确保我的网络服务只能通过我的应用访问。
我的背景是PHP。在PHP中,我不需要担心这样的事情,因为一切都在服务器上运行。
在Java和特别是Android编程的情况下,情况有所不同。即使加密。每个人都可以打开一个APK,看看如何访问Web服务。那么有没有办法隐藏或混淆对Web服务的访问,所以只有我的应用程序才能使用它?
出于测试目的,我没有添加任何安全性或加密。这是我现在正在做的Web服务器的基本调用:
String url = "http://thisismyurl.com/a.php?action=get";
String result = Web.executeWeb(url);
public class Web {
public static String executeWeb(final String url) {
final StringBuilder sb = new StringBuilder();
Thread thread = new Thread(new Runnable() {
public void run()
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String result, line = reader.readLine();
result = line;
while((line=reader.readLine())!=null){
result+=line;
}
sb.append(result);
//System.out.println(result);
//Log.i("My Response :: ", result);
} catch (Exception e)
{
// TODO: handle exception
}
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}
}
我如何将其隐藏在黑客的窥探之中? ;-)甚至可能吗?
提前致谢!
答案 0 :(得分:1)
使用TLS内的(自签名)证书部署客户端身份验证。
这种配置可以在大多数Web服务器和Java应用程序服务器上启用,您通常也可以配置Web或应用程序服务器,以便您可以检索客户端用于验证的私钥证书。本身。
请注意,HTTPS在任何网络流量之前使用SSL(或现在的TLS),因此您无法在应用程序中对此进行编程,它确实需要服务器配置。
检查this link如何配置Apache 2。
答案 1 :(得分:0)
使用您的应用程序ID(如IMEI)作为您的Web服务调用中的参数。您需要在服务器端的数据库中创建一个表,该表将存储所有已注册的设备。现在只有这些注册的设备可以访问您的Web服务。这是我的想法,也应该有其他想法。