throws org.opensaml.xml.security.SecurityException, WSSecurityException {
if (keyInfo.getElement() != null) {
return (KeyInfo)OpenSAMLUtil.fromDom(keyInfo.getElement());
} else {
// Set the certificate or public key
BasicX509Credential keyInfoCredential = new BasicX509Credential();
if (keyInfo.getCertificate() != null) {
keyInfoCredential.setEntityCertificate(keyInfo.getCertificate());
} else if (keyInfo.getPublicKey() != null) {
keyInfoCredential.setPublicKey(keyInfo.getPublicKey());
}
// Configure how to emit the certificate
X509KeyInfoGeneratorFactory kiFactory = new X509KeyInfoGeneratorFactory();
KeyInfoBean.CERT_IDENTIFIER certIdentifier = keyInfo.getCertIdentifer();