Java Key Public getPublic(byte[] encodedKey)

Here you can find the source of getPublic(byte[] encodedKey)

Description

The method gets the public key from the encoded byte.

License

Open Source License

Parameter

Parameter Description
encodedKey the encoded public key in bytes.

Declaration

public static PublicKey getPublic(byte[] encodedKey) throws InvalidKeySpecException 

Method Source Code


//package com.java2s;
import java.security.KeyFactory;

import java.security.PublicKey;

import java.security.spec.InvalidKeySpecException;

import java.security.spec.X509EncodedKeySpec;

public class Main {
    private static KeyFactory kf;

    /**/*w w w  .  j a v a 2s  . c o  m*/
     * The method gets the public key from the encoded byte.
     * The bytes can be recovered from a Hex string saved in a file etc.
     * @param encodedKey the encoded public key in bytes.
     */
    public static PublicKey getPublic(byte[] encodedKey) throws InvalidKeySpecException {
        return kf.generatePublic(new X509EncodedKeySpec(encodedKey));
    }
}

Related

  1. getPublic(byte[] keyBytes)
  2. getPublicBytes(KeyPair keyPair)
  3. getPublicDeclaredMethods(Class clz)
  4. getPublicDeclaredMethods(Class clz)