简体   繁体   English

Android:与数据库的安全连接

[英]Android: Secure connection with a database

I'm developing an Android app. 我正在开发一个Android应用程序。 When the user pushes a button, I wanna add the unique identifier of the Android device and some other data to a database. 当用户按下按钮时,我想将Android设备的唯一标识符和一些其他数据添加到数据库中。

The problem is: How can I prevent that other applications / websites etc. can put data into my database. 问题是:如何防止其他应用程序/网站等将数据放入数据库。

I was thinking about a SSL connection, but also other apps could use a SSL connection to connect to my database. 我当时在考虑使用SSL连接,但是其他应用程序也可以使用SSL连接来连接到我的数据库。 The next what came up in my mind was creation an extra field, use a salt and encrypt the unique id + other data + salt and check on the db server if the encrypted information matches. 我接下来想到的是创建一个额外的字段,使用一个salt并对唯一的id +其他数据+ salt进行加密,然后在db服务器上检查加密信息是否匹配。

But in theory is it possible to reverse engineer an Android app, so 'they' could find my salt and also send the encrypted information to my db. 但是从理论上讲,可以对Android应用程序进行反向工程,因此“他们”可以找到我的想法,并将加密的信息发送到我的数据库。

How can I make a php script to save information into a db, and make it only usable for just my own application? 我如何制作一个php脚本以将信息保存到db中,并使其仅可用于我自己的应用程序?

If this data is per-device, then on first run create a "cookie", eg a long-enough random ID that you use on subsequent communication with server. 如果此数据是针对每个设备的,则在第一次运行时,创建一个“ cookie”,例如,您在与服务器的后续通信中使用的足够长的随机ID。 And also use SSL so no one can snoop on the traffic. 并且还使用SSL,因此没有人可以监听流量。

To generate random string use UUID . 要生成随机字符串,请使用UUID

You could use Settings.Secure.ANDROID_ID , but if someone reverses your protocol, they could create an app that piggybacks the exploit. 您可以使用Settings.Secure.ANDROID_ID ,但是如果有人撤消了您的协议​​,他们可以创建一个背负漏洞利用的应用程序。 Unlikely but doable. 不太可能但可行。

OTOH, if data is per user, then you need to create a login system. OTOH,如果数据是每个用户的,那么您需要创建一个登录系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM