简体   繁体   English

Android在哪里保存个人数据?

[英]Android where to save personal data?

我有一个两难的境地,我需要在我的Android设备上保存一些安全数据,这些数据是个人机柜的登录信息,所以请你给我一个建议,哪里更好地将这些信息保存到简单的txt文件中(但安全性如何? ?)或者Android平台中是否存在MySQL DB的模拟(以及我如何访问它)?

The best way to store personal data in Android application is using shared preferences with mode private, so that nobody can access that data other than your application. 在Android应用程序中存储个人数据的最佳方法是使用私有模式的共享首选项,这样任何人都无法访问除应用程序之外的其他数据。 for more details see Android developers tips about shared preferences here. 有关详细信息,请参阅有关共享偏好Android开发技巧在这里。

You can save the simple txt file into your application directory. 您可以将简单的txt文件保存到应用程序目录中。 In General, Android assigns each application a unique uid. 通常,Android会为每个应用程序分配一个唯一的uid。 Each application has its own application directory with mode 660. So other application cannot access its content. 每个应用程序都有自己的应用程序目录,模式为660.因此其他应用程序无法访问其内容。 To write your own application directory, you can use the following code: 要编写自己的应用程序目录,可以使用以下代码:

String filename = "myfile";
String string = "Your security content";
FileOutputStream outputStream;

try {
  outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
  string = encrypt(string);
  outputStream.write(string.getBytes());
  outputStream.close();
} catch (Exception e) {
  e.printStackTrace();
}

However, if the target device is a rooted device, other application can access your file. 但是,如果目标设备是root设备,则其他应用程序可以访问您的文件。 So a better approach is to encrypt your data, and save it into the application directory. 因此,更好的方法是加密数据,并将其保存到应用程序目录中。

For a database approach, it has the same problem, you can define your own content provider without exporting it out, but it is still vulnerable on a rooted device. 对于数据库方法,它有同样的问题,您可以定义自己的内容提供程序而不将其导出,但在root设备上仍然容易受到攻击。 So whatever you choose, writing txt file or storing it on DB, encrypt it first is necessary. 所以无论你选择什么,编写txt文件或将其存储在DB上,首先加密它是必要的。

AFAIK you cannot run MySQL on a android device but you can use SQLite ( tutorial ). AFAIK你不能在Android设备上运行MySQL,但你可以使用SQLite教程 )。 You could even try using SQLCipher to store it in a encrypted database. 您甚至可以尝试使用SQLCipher将其存储在加密数据库中。 Although I'm told it's not too hard to extract the access key from your APK. 虽然我被告知从你的APK中提取访问密钥并不太难。

When you store you password, make sure you encrypt it (even if you are encrypting the database). 当您存储密码时,请确保对其进行加密(即使您正在加密数据库)。 Storing passwords as plain text is rarely a good idea ;) 将密码存储为纯文本很少是个好主意;)

Whatever you do, do NOT store it in a text file! 无论你做什么,都不要将它存储在文本文件中!

You could store the details in the SQLdb on android but save all the form details using encryption and just persist the strings. 您可以将详细信息存储在Android上的SQLdb中,但使用加密保存所有表单详细信息并仅保留字符串。

You can see in the answer below an example of someone doing this exact same technique and using the phoneId for the encryption (although I'm not sure how safe that really is). 你可以在下面的答案中看到一个人做同样技术并使用phoneId进行加密的例子(虽然我不确定它到底有多安全)。

Is it safe to store username + passwords in a local SQLite db in Android? 在Android中的本地SQLite数据库中存储用户名+密码是否安全?

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

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