public static byte[] generateX509PublicKey(BigInteger modulus,BigInteger publicExponent) throws Exception {
  RSAPublicKeySpec rsaPublicKeySpec=new RSAPublicKeySpec(modulus,publicExponent);
  PublicKey javaRsaPublicKey=KEY_FACTORY.generatePublic(rsaPublicKeySpec);
  return generateX509PublicKey(javaRsaPublicKey);
}

public static byte [ ] generateX509PublicKey ( BigInteger modulus , BigInteger publicExponent ) throws Exception { RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec ( modulus , publicExponent ) ; PublicKey javaRsaPublicKey = KEY_FACTORY . generatePublic ( rsaPublicKeySpec ) ; return generateX509PublicKey ( javaRsaPublicKey ) ; }
generates x509 encoded public key bytes from a given modulus and public exponent .
