Here you can find the source of getPublicKey(KeyPair keyPair)
public static String getPublicKey(KeyPair keyPair)
//package com.java2s; //License from project: Apache License import java.security.KeyPair; import java.security.PublicKey; public class Main { private static char[] HEXCHAR = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String getPublicKey(KeyPair keyPair) { PublicKey publicKey = keyPair.getPublic(); return toHexString(publicKey.getEncoded()); }//from w w w. j a va2s. c om public static String toHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { sb.append(HEXCHAR[(bytes[i] & 0xf0) >>> 4]); sb.append(HEXCHAR[bytes[i] & 0x0f]); } return sb.toString(); } }