在运行时将敏感数据存储在Java(Android)中



在运行时将敏感数据(密码等(存储在通常的变量中吗?
我的意思是这样:

public class MainActivity extends AppCompatActivity {
// ...
    String password; // this is my password
// ...
    public void click(View v) { // on some button click
       password = txtPassword.getText().toString(); // txtPassword is an EditText field
// ...
    }
    void someMethod() {
        Intent intent = new Intent(this, SomeActivity.class);
        intent.putExtra(password); // password needs to be passed to other activities
        startActivity(intent);
    }
// ...
}

必须存储此密码,直到用户退出应用程序为止。几乎每个活动都需要它,所以我必须在调用新活动时通过它来通过它。

像上面的示例一样存储password安全吗?如果不是这样,我该怎么做?

问题不是您在代码中使用密码,而是如何检索它。例如,如果您从没有任何加密的情况下从API中检索数据,则有人可以窃取网络中的软件包并获取密码。另一件事是,如果您将paswoord保存在共享的首选项中,那么如果您可以访问手机UNE远程终端,则很容易将其钢化。因此,如果您想与密码一起保存,请从安全的API中检索它,并在所有过程中使用加密以避免任何类型的钢。之后,您可以按照您的意愿在应用程序的逻辑中使用它

最新更新