Class AbstractDOMSignatureMethod

java.lang.Object
org.apache.jcp.xml.dsig.internal.dom.DOMStructure
org.apache.jcp.xml.dsig.internal.dom.AbstractDOMSignatureMethod
All Implemented Interfaces:
AlgorithmMethod, SignatureMethod, XMLStructure
Direct Known Subclasses:
DOMHMACSignatureMethod, DOMSignatureMethod

abstract class AbstractDOMSignatureMethod extends DOMStructure implements SignatureMethod
An abstract class representing a SignatureMethod. Subclasses implement a specific XML DSig signature algorithm.
  • Constructor Details

    • AbstractDOMSignatureMethod

      AbstractDOMSignatureMethod()
  • Method Details

    • verify

      abstract boolean verify(Key key, SignedInfo si, byte[] sig, XMLValidateContext context) throws InvalidKeyException, SignatureException, XMLSignatureException
      Verifies the passed-in signature with the specified key, using the underlying Signature or Mac algorithm.
      Parameters:
      key - the verification key
      si - the SignedInfo
      sig - the signature bytes to be verified
      context - the XMLValidateContext
      Returns:
      true if the signature verified successfully, false if not
      Throws:
      NullPointerException - if key, si or sig are null
      InvalidKeyException - if the key is improperly encoded, of the wrong type, or parameters are missing, etc
      SignatureException - if an unexpected error occurs, such as the passed in signature is improperly encoded
      XMLSignatureException - if an unexpected error occurs
    • sign

      abstract byte[] sign(Key key, SignedInfo si, XMLSignContext context) throws InvalidKeyException, XMLSignatureException
      Signs the bytes with the specified key, using the underlying Signature or Mac algorithm.
      Parameters:
      key - the signing key
      si - the SignedInfo
      context - the XMLSignContext
      Returns:
      the signature
      Throws:
      NullPointerException - if key or si are null
      InvalidKeyException - if the key is improperly encoded, of the wrong type, or parameters are missing, etc
      XMLSignatureException - if an unexpected error occurs
    • getJCAAlgorithm

      abstract String getJCAAlgorithm()
      Returns the java.security.Signature or javax.crypto.Mac standard algorithm name.
    • getAlgorithmType

      abstract AbstractDOMSignatureMethod.Type getAlgorithmType()
      Returns the type of signature algorithm.
    • marshal

      public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) throws MarshalException
      This method invokes the marshalParams method to marshal any algorithm-specific parameters.
      Specified by:
      marshal in class DOMStructure
      Throws:
      MarshalException
    • marshalParams

      void marshalParams(Element parent, String paramsPrefix) throws MarshalException
      Marshals the algorithm-specific parameters to an Element and appends it to the specified parent element. By default, this method throws an exception since most SignatureMethod algorithms do not have parameters. Subclasses should override it if they have parameters.
      Parameters:
      parent - the parent element to append the parameters to
      paramsPrefix - the algorithm parameters prefix to use
      Throws:
      MarshalException - if the parameters cannot be marshalled
    • unmarshalParams

      SignatureMethodParameterSpec unmarshalParams(Element paramsElem) throws MarshalException
      Unmarshals SignatureMethodParameterSpec from the specified Element. By default, this method throws an exception since most SignatureMethod algorithms do not have parameters. Subclasses should override it if they have parameters.
      Parameters:
      paramsElem - the Element holding the input params
      Returns:
      the algorithm-specific SignatureMethodParameterSpec
      Throws:
      MarshalException - if the parameters cannot be unmarshalled
    • checkParams

      Checks if the specified parameters are valid for this algorithm. By default, this method throws an exception if parameters are specified since most SignatureMethod algorithms do not have parameters. Subclasses should override it if they have parameters.
      Parameters:
      params - the algorithm-specific params (may be null)
      Throws:
      InvalidAlgorithmParameterException - if the parameters are not appropriate for this signature method
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • paramsEqual

      boolean paramsEqual(AlgorithmParameterSpec spec)
      Returns true if parameters are equal; false otherwise. Subclasses should override this method to compare algorithm-specific parameters.