org.keycloak.saml.processing.core.saml.v2.util

## Class SignatureUtil

- java.lang.Object
- - org.keycloak.saml.processing.core.saml.v2.util.SignatureUtil

-     public class SignatureUtil
      extends Object

  Signature utility for signing content
  Since:
    Dec 16, 2008
  Author:
    Anil.Saldhana@redhat.com

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SignatureUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static KeyValueType` | `createKeyValue(PublicKey key)` Creates a `KeyValueType` that wraps the specified public key.
    `static DSAKeyValueType` | `getDSAKeyValue(Element element)` Given a dsig:DSAKeyValue element, return `DSAKeyValueType`
    `static RSAKeyValueType` | `getRSAKeyValue(Element element)` Given a dsig:DSAKeyValue element, return `DSAKeyValueType`
    `static String` | `getXMLSignatureAlgorithmURI(String algo)` Get the XML Signature URI for the algo (RSA, DSA)
    `static void` | `marshall(SignatureType signature, OutputStream os)` Marshall a SignatureType to output stream
    `static byte[]` | `sign(String stringToBeSigned, PrivateKey signingKey)` Sign a string using the private key
    `static boolean` | `validate(byte[] signedContent, byte[] signatureValue, PublicKey validatingKey)` Validate the signed content with the signature value
    `static boolean` | `validate(byte[] signedContent, byte[] signatureValue, String signatureAlgorithm, X509Certificate validatingCert)` Validate the signature using a x509 certificate

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SignatureUtil

          public SignatureUtil()

  - ### Method Detail

    - #### marshall

          public static void marshall(SignatureType signature,
                                      OutputStream os)
                               throws JAXBException,
                                      SAXException

      Marshall a SignatureType to output stream
      Parameters:
        `signature` -
        `os` -
      Throws:
        `SAXException`
        `JAXBException`

    - #### getXMLSignatureAlgorithmURI

          public static String getXMLSignatureAlgorithmURI(String algo)

      Get the XML Signature URI for the algo (RSA, DSA)
      Parameters:
        `algo` -
      Returns:

    - #### sign

          public static byte[] sign(String stringToBeSigned,
                                    PrivateKey signingKey)
                             throws GeneralSecurityException

      Sign a string using the private key
      Parameters:
        `stringToBeSigned` -
        `signingKey` -
      Returns:
      Throws:
        `GeneralSecurityException`

    - #### validate

          public static boolean validate(byte[] signedContent,
                                         byte[] signatureValue,
                                         PublicKey validatingKey)
                                  throws GeneralSecurityException

      Validate the signed content with the signature value
      Parameters:
        `signedContent` -
        `signatureValue` -
        `validatingKey` -
      Returns:
      Throws:
        `GeneralSecurityException`

    - #### validate

          public static boolean validate(byte[] signedContent,
                                         byte[] signatureValue,
                                         String signatureAlgorithm,
                                         X509Certificate validatingCert)
                                  throws GeneralSecurityException

      Validate the signature using a x509 certificate
      Parameters:
        `signedContent` -
        `signatureValue` -
        `signatureAlgorithm` -
        `validatingCert` -
      Returns:
      Throws:
        `GeneralSecurityException`

    - #### getDSAKeyValue

          public static DSAKeyValueType getDSAKeyValue(Element element)
                                                throws ParsingException

      Given a dsig:DSAKeyValue element, return `DSAKeyValueType`
      Parameters:
        `element` -
      Returns:
      Throws:
        `ParsingException`

    - #### getRSAKeyValue

          public static RSAKeyValueType getRSAKeyValue(Element element)
                                                throws ParsingException

      Given a dsig:DSAKeyValue element, return `DSAKeyValueType`
      Parameters:
        `element` -
      Returns:
      Throws:
        `ParsingException`

    - #### createKeyValue

          public static KeyValueType createKeyValue(PublicKey key)

      Creates a `KeyValueType` that wraps the specified public key. This method supports DSA and RSA keys.

      Parameters:
        `key` - the `PublicKey` that will be represented as a `KeyValueType`.
      Returns:
        the constructed `KeyValueType` or `null` if the specified key is neither a DSA nor a RSA key.

Copyright © 2016 JBoss by Red Hat. All rights reserved.