Java Key Public getPublicKey(KeyPair keyPair)

Here you can find the source of getPublicKey(KeyPair keyPair)

Description

get Public Key

License

Apache License

Declaration

public static String getPublicKey(KeyPair keyPair) 

Method Source Code

//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();
    }
}

Related

  1. getPublicKey(byte[] keyBytes, String algorithm)
  2. getPublicKey(final byte[] keyData)
  3. getPublicKey(final byte[] modulus, final byte[] exponent)
  4. getPublicKey(final String algorithm, final File publicKeyFile)
  5. getPublicKey(KeyPair keyPair)
  6. getPublicKey(KeyPair kp)
  7. getPublicKey(KeyStore keyStore, String alias)
  8. getPublicKey(KeyStore keyStore, String alias)
  9. getPublicKey(KeyStore keyStore, String alias, char[] password)