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

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