*/
public static PublicKey getKey(DEREncodedKeyValue keyValue) throws KeyException{
String[] supportedKeyTypes = { "RSA", "DSA", "EC"};
if (keyValue.getValue() == null) {
throw new KeyException("No data found in key value element");
}
byte[] encodedKey = Base64.decode(keyValue.getValue());
// Iterate over the supported key types until one produces a public key.
for (String keyType : supportedKeyTypes) {
try {
KeyFactory keyFactory = KeyFactory.getInstance(keyType);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
PublicKey publicKey = keyFactory.generatePublic(keySpec);
if (publicKey != null) {
return publicKey;
}
} catch (NoSuchAlgorithmException e) {
// ignore
} catch (InvalidKeySpecException e) {
// ignore
}
}
throw new KeyException("DEREncodedKeyValue did not contain a supported key type");
}