echen echen - 1 year ago 133
Java Question

Mac OS X Keychain access in Java for Generic Passwords

What is the standard way to retrieve generic passwords in the Keychain of OS X using only Java? Apple Developer Pages provide some good background but the implementation and examples are in C or native code unfortunately.

The Java KeyStore OS X implementation appears to be good only for public/private key pairs and certs but not generic username/password combos.

I see a project started Here: but it is relatively old and not actively maintained.

Is there a more state of the art solution to the problem of securing credentials in Mac OS X in Java?

EDIT: OAuth is not an option for the class of problem and environment that I am operating in ...

Answer Source

Further to the answer above by f-stephen-q, this library appears to work well still. I'm using a fork of it which is mavenised

$ git clone
$ mvn install
$ cp dist/osxkeychain.jar ~/myproject/external

Adding a dependency


Running it

osx-keychain-java$ jshell -cp ./dist/osxkeychain.jar

jshell> import*;
jshell> OSXKeychain keychain = OSXKeychain.getInstance();
keychain ==>

jshell> keychain.addGenericPassword("aardvark", "a", "b");

jshell> keychain.findGenericPassword("aardvark", "a");
$4 ==> "b"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download