简体   繁体   English

如何停止从Android中的另一个应用程序访问共享的首选项

[英]How to stop accessing shared preferences from another application in android

I have an application where I want to save username and password on Remember checkbox is checked. 我有一个应用程序,要在其中保存用户名和密码,请记住记住复选框已选中。

I done the above requirement using Shared Preferences. 我使用共享首选项完成了以上要求。 But i created another application and tried to read the username and password and got the values successfully. 但是我创建了另一个应用程序,尝试读取用户名和密码并成功获取了值。

My Client needs the security so how can i stop other apps to read my shared preferences. 我的客户需要安全性,因此我该如何停止其他应用程序读取我的共享首选项。

public SharedPreferences getSharedPreferences()
{
   return this.mContext.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE);
}
public void saveLong(String paramString, long paramLong)
{
    SharedPreferences.Editor localEditor = getSharedPreferences().edit();
    localEditor.putLong(paramString, paramLong);
    localEditor.commit();
} 

If MODE_PRIVATE is not enough, you can encrypt the data, turn it into base64 , and save it as a string in the Preferences object. 如果MODE_PRIVATE还不够,则可以加密数据,将其转换为base64 ,并将其另存为字符串在Preferences对象中。 Reverse the process on the way back. 在返回的过程中逆转该过程。 Your data will be accessible, but illegible. 您的数据将可访问,但难以辨认。

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

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