public static PublicKey buildKey(KeySpec keySpec, String keyAlgorithm) throws KeyException {
try {
KeyFactory keyFactory = KeyFactory.getInstance(keyAlgorithm);
return keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
throw new KeyException(keyAlgorithm + "algorithm is not supported by the JCE", e);
} catch (InvalidKeySpecException e) {
throw new KeyException("Invalid key information", e);
}
}