public static byte[] generateX509PublicKey(PublicKey publicKey) throws Exception {
  X509EncodedKeySpec x509EncodedPublicKey=KEY_FACTORY.getKeySpec(publicKey,X509EncodedKeySpec.class);
  return x509EncodedPublicKey.getEncoded();
}

public static byte [ ] generateX509PublicKey ( PublicKey publicKey ) throws Exception { X509EncodedKeySpec x509EncodedPublicKey = KEY_FACTORY . getKeySpec ( publicKey , X509EncodedKeySpec . class ) ; return x509EncodedPublicKey . getEncoded ( ) ; }
generates x509 encoded public key bytes from a given public key .
