Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 957
نمايش فراداده

SSLContextjavax.net.ssl

Java 1.4

This class is a factory for socket and server socket factories. Although most applications do not need to use this class directly, it is the central class of the javax.net.ssl package. Most applications use the default SSLSocketFactory and SSLServerSocketFactory objects returned by the static getdefault( ) methods of those classes. Applications that want to perform SSL networking using a security provider other than the default provider, or that want to customize key management or trust management for the SSL connection should use custom socket factories created from a custom SSLContext. In Java 5.0, this class also includes createSSLEngine( ) factory methods for creating SSLEngine objects.

Create an SSLContext by passing the name of the desired secure socket protocol and, optionally, the desired provider to getInstance( ). The default "SunJSSE" provider supports protocol strings "SSL", "SSLv2", "SSLv3", "TLS", and "TLSv1". Once you have created an SSLContext object, call its init( ) method to supply the KeyManager, trustManager, and SecureRandom objects it requires. If any of the init( ) arguments is null, a default value will be used. Finally, obtain a SSLSocketFactory and SSLServerSocketFactory by calling getSocketFactory( ) and getServerSocketFactory( ).

public class

SSLContext { // Protected Constructors protected

SSLContext (SSLContextSpi

contextSpi , java.security.Provider

provider , String

protocol ); // Public Class Methods public static SSLContext

getInstance (String

protocol ) throws java.security.NoSuchAlgorithmException; public static SSLContext

getInstance (String

protocol , String

provider ) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException; public static SSLContext

getInstance (String

protocol , java.security.Provider

provider ) throws java.security.NoSuchAlgorithmException; // Public Instance Methods

5.0 public final SSLEngine

createSSLEngine ( );

5.0 public final SSLEngine

createSSLEngine (String

peerHost , int

peerPort ); public final SSLSessionContext

getClientSessionContext ( ); public final String

getProtocol ( ); public final java.security.Provider

getProvider ( ); public final SSLSessionContext

getServerSessionContext ( ); public final SSLServerSocketFactory

getServerSocketFactory ( ); public final SSLSocketFactory

getSocketFactory ( ); public final void

init (KeyManager[ ]

km , TrustManager[ ]

tm , java.security.SecureRandom

random ) throws java.security.KeyManagementException; }