private static final PublicKey constructPublicKey(byte[] encodedKey,String encodedKeyAlgorithm) throws InvalidKeyException, NoSuchAlgorithmException {
  try {
    KeyFactory keyFactory=KeyFactory.getInstance(encodedKeyAlgorithm);
    X509EncodedKeySpec keySpec=new X509EncodedKeySpec(encodedKey);
    return keyFactory.generatePublic(keySpec);
  }
 catch (  NoSuchAlgorithmException nsae) {
    throw new NoSuchAlgorithmException("No installed providers " + "can create keys for the " + encodedKeyAlgorithm + "algorithm",nsae);
  }
catch (  InvalidKeySpecException ike) {
    throw new InvalidKeyException("Cannot construct public key",ike);
  }
}

private static final PublicKey constructPublicKey ( byte [ ] encodedKey , String encodedKeyAlgorithm ) throws InvalidKeyException , NoSuchAlgorithmException { try { KeyFactory keyFactory = KeyFactory . getInstance ( encodedKeyAlgorithm ) ; X509EncodedKeySpec keySpec = new X509EncodedKeySpec ( encodedKey ) ; return keyFactory . generatePublic ( keySpec ) ; } catch ( NoSuchAlgorithmException nsae ) { throw new NoSuchAlgorithmException ( "No installed providers " + "can create keys for the " + encodedKeyAlgorithm + "algorithm" , nsae ) ; } catch ( InvalidKeySpecException ike ) { throw new InvalidKeyException ( "Cannot construct public key" , ike ) ; } }
construct a public key from its encoding .
