Storing username/password on Mac using Java

只愿长相守 提交于 2019-11-30 07:27:20

There is Java keychain API, in that there's an implementation of KeyStore on OS X backed by the keychain.

I think the keychain is the best place (if not the place) to store the password. It's encrypted with a good algorithm, the user is free to be as permissive or as paranoid over the availability of the keychain to apps as they like, and the password would then be stored with and configured like all of the other passwords the user stores.

I haven't tried this, but it looks like you can access the key chain with the Apple crypto provider (com.apple.crypto.provider.Apple), creating a KeyStore of type KeychainStore.


Okay, after some experimentation, I was able to access private-key–certificate entries in the KeychainStore. However, passwords in my Keychain did not show up (no alias was listed), and when I tried to add a KeyStore.SecretKeyEntry (which is what you'd need to hold a password) it failed with the message, "Key is not a PrivateKey". Clearly, Apple has not supported SecretKeyEntry.

If you still want to protect your Twitter password through the key chain, I think the closest you can get is to generate an RSA key pair, self-sign a certificate, and add a PrivateKeyEntry to the keychain. Then you can use the key pair to protect the Twitter password.

It isn't terribly difficult to sign certificates yourself, but if you go that route, you might want to check out the BouncyCastle library for help.

You should take a look at twitters API page on OAuth support. By using OAuth, you don't need to know the user's twitter password.

http://apiwiki.twitter.com/OAuth-FAQ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!