KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > security > cert > X509Certificate

javax.security.cert
Class X509Certificate

java.lang.Object
  extended by javax.security.cert.Certificate
      extended by javax.security.cert.X509Certificate
See Also:
Top Examples, Source Code, X509Extension

public abstract void checkValidity()
                            throws CertificateExpiredException,
                                   CertificateNotYetValidException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[238]Sets up an SSL socket to securely communicate with a Web server, using the HTTPS protocol
By Anonymous on 2003/04/25 14:43:42  Rate
//The following code sets up an SSL socket to securely communicate with a Web server, using the HTTPS protocol: 
  
  
  
 import javax.net.ssl.*; 
 import java.io.*; 
    
 // Get a SocketFactory object for creating SSL sockets 
 SSLSocketFactory factory =  ( SSLSocketFactory )  SSLSocketFactory.getDefault (  ) ; 
  
  
 // Create a secure socket connected to the HTTPS port  ( port 443 )  of a server 
 SSLSocket sslsock =  ( SSLSocket )  factory.createSocket ( hostname, 443 ) ; 
  
  
 // Get the certificate presented by the web server. This may throw an  
 // exception if the server didn't supply a certificate. Look at the 
 // issuer of the certificate and decide if it is trusted. 
 SSLSession session = sslsock.getSession (  ) ; 
 X509Certificate cert =  ( X509Certificate ) session.getPeerCertificates (  )  [ 0 ] ; 
 String issuer = cert.getIssuerDN (  ) .getName (  ) ;  
  
  
 // Assuming we trust the certificate, we now use the socket just like a normal 
 // java.net.Socket object. So send a HTTP request and read the response 
 PrintWriter out = new PrintWriter ( sslsock.getOutputStream (  )  ) ; 
 out.print ( "GET " + args [ 1 ]  + " HTTP/1.0\r\n\r\n" ) ; 
 out.flush (  ) ; 
  
  
 // Next, read the server's response and print it to the console. 
 BufferedReader in = 
   new BufferedReader ( new InputStreamReader ( sslsock.getInputStream (  )  )  ) ; 
 String line; 
 while (  ( line = in.readLine (  )  )  != null )  System.out.println ( line ) ; 
  
  
 // Finally, close the socket. 
 sslsock.close (  ) ;  
  
  
 //checkValidity


public abstract void checkValidity(Date date)
                            throws CertificateExpiredException,
                                   CertificateNotYetValidException
See Also:
checkValidity()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final X509Certificate getInstance(byte[] certData)
                                         throws CertificateException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final X509Certificate getInstance(InputStream inStream)
                                         throws CertificateException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Principal getIssuerDN()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Date getNotAfter()
See Also:
checkValidity()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Date getNotBefore()
See Also:
checkValidity()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract BigInteger getSerialNumber()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract String getSigAlgName()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract String getSigAlgOID()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract byte[] getSigAlgParams()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Principal getSubjectDN()
See Also:
getIssuerDN()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract int getVersion()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public X509Certificate()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags