Android:存储HTTP基本密码/用户名

问题描述:

我有一个简单的RESTful后端,并且正在使用HTTP Basic over HTTPS进行身份验证.效果很好,但是我正在寻找一种适当的解决方案来存储凭据(用户名+密码).

I have a simple RESTful backend and I am using HTTP Basic over HTTPS for authentication. It works fine, but I am looking for a appropriate solution to store the credentials (username + password).

那里有很多示例,大多数都建议使用Account Manager来存储密码. AFAIK帐户管理器仅存储OAUTH(和类似)帐户,并自动生成令牌等.但是,如何使用它来存储和获取原始密码?甚至有可能吗?

There are a lot of examples out there and the majority suggest to use the Account Manager to store passwords. AFAIK the account manager stores only OAUTH (and similar) accounts and automatically generates tokens etc. But how can I use it to store and fetch the original passwords? Is it even possible?

其他人建议将其存储为散列值,但这对我来说没有意义(最终,我将需要访问原始字符串).

Others suggest to store it as a hashed value, but this doesn't make sense to me (At the end of the day I will need to have access to the original string).

很抱歉另一个How to use HTTP basic and android问题,但是到目前为止我还找不到合适的答案并将数据存储在本地sqlite db中,因为纯文本似乎不合适.

Sorry for another How to use HTTP basic and android question, but I was not able to find a suitable answer so far and to store the data within the local sqlite db as plaintext doesn't seem to be appropriate.

当然,您也可以使用Account Manager来存储密码.这是方法:

Of course you can use the Account Manager to store password as well. This is the method:

addAccountExplicitly (Account account, String password, Bundle userdata)

,您可以使用以下方法获取密码:

and you can get the password using this method:

getPassword(Account account)