Here you can find the source of getPublic(byte[] encodedKey)
Parameter | Description |
---|---|
encodedKey | the encoded public key in bytes. |
public static PublicKey getPublic(byte[] encodedKey) throws InvalidKeySpecException
//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)); } }