* @throws NoSuchAlgorithmException if the key type is unsupported
* @throws InvalidKeySpecException if the key type does not support X.509 SPKI encoding
*/
public static void addDEREncodedPublicKey(KeyInfo keyInfo, PublicKey pk)
throws NoSuchAlgorithmException, InvalidKeySpecException {
DEREncodedKeyValue keyValue = (DEREncodedKeyValue) Configuration.getBuilderFactory()
.getBuilder(DEREncodedKeyValue.DEFAULT_ELEMENT_NAME)
.buildObject(DEREncodedKeyValue.DEFAULT_ELEMENT_NAME);
KeyFactory keyFactory = KeyFactory.getInstance(pk.getAlgorithm());
X509EncodedKeySpec keySpec = keyFactory.getKeySpec(pk, X509EncodedKeySpec.class);
keyValue.setValue(Base64.encodeBytes(keySpec.getEncoded()));
keyInfo.getXMLObjects().add(keyValue);
}