正如我在評論中所說的,在answer to one of your questions earlier中,您需要使用KeyManager
來執行此操作。
這樣做有很多種方法。 jSSLutils是一個庫,可以使它更方便一些(但你也可以更手動地做)。有一個FixedServerAliasKeyManager的例子。最簡單的方法之一是使用這樣的東西:
X509SSLContextFactory sslContextFactory = new X509SSLContextFactory();
// By default, this would use the keystore passed with the usual system properties.
sslContextFactory.setKeyManagerWrapper(
new FixedServerAliasKeyManager.Wrapper("the-alias-you-want"));
// You could read the alias name from a custom system property, for example.
SSLContext sslContext = sslContextFactory.buildSSLContext("TLS");
SSLServerSocketFactory sslServerSocketFactory = sslContext.getServerSocketFactory();
請參閱:http://stackoverflow.com/questions/1788031 – Thor 2011-06-16 16:06:05