如何从 SSLContext 检索 keyManager 详细信息?
How to retrieve keyManager details from SSLContext?
我想从 sslContext 对象中检索属于 keyManager 的 credentialMap。
public static void main(String[] args) throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, NoSuchProviderException, KeyManagementException {
SSLContext sslContext = newServerContext(createKeyManagers());
// how to get keyManager from sslContext?
}
public static SSLContext newServerContext(KeyManager[] keyManagers)
throws NoSuchAlgorithmException, NoSuchProviderException,
KeyManagementException {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagers, null, new SecureRandom());
return ctx;
}
public static KeyManager[] createKeyManagers()
throws KeyStoreException, IOException, NoSuchAlgorithmException,
CertificateException, UnrecoverableKeyException
{
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream keyStoreFile = new FileInputStream("F:\IdeaProjects\NewFeature\keystore.jks");
String keyStorePassword = "changeit";
keyStore.load(keyStoreFile, keyStorePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, keyStorePassword.toCharArray());
return kmf.getKeyManagers();
}
如何从 ctx(SSLContext) 对象中检索 keyManager 详细信息?
看来你无法通过SSLContext
的一些方法得到KeyManager
数组。为什么不将 KeyManager
数组保存在变量中?
KeyManager[] keyManagers = createKeyManagers();
SSLContext sslContext = newServerContext(keyManagers);
对了,为什么要通过SSLContext
获得KeyManager[]
?你打算用它做什么?你打算在哪里使用它? SSLContext
充当安全套接字工厂或 SSLEngine 的工厂。 KeyManager 应该由 SSLServerSocketFactory
或 SSLEngine
内部使用。
我想从 sslContext 对象中检索属于 keyManager 的 credentialMap。
public static void main(String[] args) throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, NoSuchProviderException, KeyManagementException {
SSLContext sslContext = newServerContext(createKeyManagers());
// how to get keyManager from sslContext?
}
public static SSLContext newServerContext(KeyManager[] keyManagers)
throws NoSuchAlgorithmException, NoSuchProviderException,
KeyManagementException {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagers, null, new SecureRandom());
return ctx;
}
public static KeyManager[] createKeyManagers()
throws KeyStoreException, IOException, NoSuchAlgorithmException,
CertificateException, UnrecoverableKeyException
{
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream keyStoreFile = new FileInputStream("F:\IdeaProjects\NewFeature\keystore.jks");
String keyStorePassword = "changeit";
keyStore.load(keyStoreFile, keyStorePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, keyStorePassword.toCharArray());
return kmf.getKeyManagers();
}
如何从 ctx(SSLContext) 对象中检索 keyManager 详细信息?
看来你无法通过SSLContext
的一些方法得到KeyManager
数组。为什么不将 KeyManager
数组保存在变量中?
KeyManager[] keyManagers = createKeyManagers();
SSLContext sslContext = newServerContext(keyManagers);
对了,为什么要通过SSLContext
获得KeyManager[]
?你打算用它做什么?你打算在哪里使用它? SSLContext
充当安全套接字工厂或 SSLEngine 的工厂。 KeyManager 应该由 SSLServerSocketFactory
或 SSLEngine
内部使用。