private static SignatureMethod getSignatureMethodFromPublicKey(final PublicKey pubKey,
                                                                   final XMLSignatureFactory sigFactory) throws Exception {
        val algorithm = pubKey.getAlgorithm();
        if ("DSA".equalsIgnoreCase(algorithm)) {
            return sigFactory.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
        }
        if ("RSA".equalsIgnoreCase(algorithm)) {
            return sigFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
        }
        val format = String.format("Unsupported type of key algorithm: [%s]. Only DSA or RSA are supported", algorithm);
        throw new IllegalArgumentException(format);
    }
Sign SAML element.

@param element the element
@param privKey the priv key
@param pubKey  the pub key
@return the element
support/cas-server-support-saml-core-api/src/main/java/org/apereo/cas/support/saml/util/AbstractSamlObjectBuilder.java