How to extract public key ?

I have two tools available to me: keytool from the jdk set of executables ($JAVA_HOME/bin/keytool) and openssl. I have used openssl to create a public key certificate and a companion private key. I have successfully used keytool to import the public key certificate into my default keystore ($HOME/.keystore) to establish an entry in the keystore. I need to extract the public key out of the public key certificate (or out of the keystore entry). I need to make the public key (should be about 425 characters) available to those who want to communicate securely with me.

I cannot find a method to do this with keytool nor openssl (the openssl documentation is a little sparse).

Thanks for help.

[713 byte] By [BCScomputersTXa] at [2007-11-26 20:09:00]
# 1
if you created the private key like (rsa example):openssl genrsa -out private.pem 2048then you can extract the public key using:openssl rsa -in private.pem -pubout -outform DER -out public.der
fforstera at 2007-7-9 23:11:59 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2

Or you can do it in Java:

KeyStore ks = KeyStore.getInstance("JKS");

FileInputStream ksfis = new FileInputStream(keystoreName);

BufferedInputStream ksbufin = new BufferedInputStream(ksfis);

char[] passwd; // keystore password

ks.load(ksbufin, passwd);

java.security.cert.Certificate cert = ks.getCertificate(alias);

PublicKey publicKey = cert.getPublicKey();

byte[] encodedKey = publicKey.getEncoded();

FileOutputStream fos = new FileOutputStream("publicKey");

fos.write(encodedKey);

fos.close();

This will store it in X509EncodedKeySpec.

fforstera at 2007-7-9 23:11:59 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...