use public key and cipher suite from server cert to encrypt

I am a beginner with JSSE so please do share your wisdom. :-)

The segment of codes below is the starting point. I need to be able to use the public key and the cipher suite from the server certificate to encrypt something. Which APIs should I use? Code samples would be great.

Thousands Thanks in advance. :-)

SSLContext context = SSLContext.getInstance("SSL", new com.sun.net.ssl.internal.ssl.Provider());

context.init(null, null, null);

SSLSocket s = (SSLSocket)context.getSocketFactory().createSocket(HOST, PORT);

s.startHandshake();

javax.security.cert.X509Certificate [] certChain = s.getSession().getPeerCertificateChain();

........

[714 byte] By [khiduc] at [2007-9-26 1:13:31]
# 1

To get the RSA public key:

PublicKey pubkey = certChain[0].getPublicKey();

The certificate does not have a cipher suite.

I'm not sure what you want to do.

You can use the private key to RSA-encrypt

something short.The SSL cipher suite does NOT

use the public key. The SSL cipher is usually RC4, DES,

3DES, etc.

Hope this helps

Brian Boyter

boyter@txdirect.net

boyter at 2007-6-29 0:10:23 > top of Java-index,Security,Cryptography...