我想使用Keystore在我即将进行的项目中。我看到有一个Keystore API在 java 。但这似乎非常复杂。
还有其他可以与 Java/Groovy 配合良好的良好 keystore 吗?
最佳答案
据我所知,没有。从我的角度来看,API 相对尽可能少地提供了它需要提供的东西。
KeyStore keyStore = keyStore.getInstance(KeyStore.getDefaultType());
keyStore.load( inputStream, storePassword.getBytes() );
// Get a key
if ( keyStore.isKeyEntry(alias) ) {
Key key = keyStore.getKey(alias, keyPassword.getBytes());
}
// Store a new key
KeyFactory keyFactory = KeyFactory.getInstance(KeyStore.getDefaultType());
KeySpec keySpec ...; // depends on what kind of key you want to create (ie. rsa, etc..)
Key key = keyFactory.generatePrivate(keySpec);
// sign the key here
Certificate certChain[] = ...; // get the cert chain
keyStore.setKeyEntry(newAlias, newKey, newKeyPassword.getBytes(), certChain);
keyStore.store(outputStream, storePassword.getBytes());
这是处理 keystore 需要执行的操作的相对最少的代码。
关于java - 最好使用的 keystore 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11297754/