Class XMLEncrypter


  • public class XMLEncrypter
    extends java.lang.Object
    Helper methods to perform XML Encryption and Decryption tasks on JAXB Elements.
    • Constructor Detail

      • XMLEncrypter

        public XMLEncrypter​(MessageSecurityProvider securityProvider,
                            javax.xml.parsers.DocumentBuilder documentBuilder,
                            javax.xml.bind.Marshaller marshaller,
                            javax.xml.bind.Unmarshaller unmarshaller)
                     throws MessageProcessingException
        Contsructor of a xml XML Encrypter.
        Parameters:
        securityProvider - the used context message security provider
        documentBuilder - the DOM Document Builder used for related messages.
        marshaller - the JAXB Marshaller used for related messages.
        unmarshaller - the JAXB Unmarshaller used for related messages.
        Throws:
        MessageProcessingException - if problems occurred initializing this helper class.
    • Method Detail

      • encryptElement

        @Deprecated
        public org.w3c.dom.Document encryptElement​(javax.xml.bind.JAXBElement<?> element,
                                                   java.util.List<java.security.cert.X509Certificate> receipients,
                                                   boolean useKeyId)
                                            throws MessageProcessingException
        Deprecated.
        Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.
        Parameters:
        element - the JAXB element to decrypt.
        receipients - a list of reciepiets of the message.
        useKeyId - if in key info should be included the shorter KeyName tag instead of X509Certificate
        Returns:
        a new DOM Document the encrypted data.
        Throws:
        MessageProcessingException - if internal problems occurred generating the data.
      • encryptElement

        public org.w3c.dom.Document encryptElement​(ContextMessageSecurityProvider.Context context,
                                                   javax.xml.bind.JAXBElement<?> element,
                                                   java.util.List<java.security.cert.X509Certificate> receipients,
                                                   boolean useKeyId)
                                            throws MessageProcessingException
        Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.
        Parameters:
        context - the message security provider context to use
        element - the JAXB element to decrypt.
        receipients - a list of reciepiets of the message.
        useKeyId - if in key info should be included the shorter KeyName tag instead of X509Certificate
        Returns:
        a new DOM Document the encrypted data.
        Throws:
        MessageProcessingException - if internal problems occurred generating the data.
      • encryptElement

        public org.w3c.dom.Document encryptElement​(ContextMessageSecurityProvider.Context context,
                                                   javax.xml.bind.JAXBElement<?> element,
                                                   java.util.List<java.security.cert.X509Certificate> receipients,
                                                   XMLEncrypter.KeyInfoType keyInfoType)
                                            throws MessageProcessingException
        Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.
        Parameters:
        context - the message security provider context to use
        element - the JAXB element to decrypt.
        receipients - a list of reciepiets of the message.
        keyInfoType - The type of keyinfo to add to the encrypted element.
        Returns:
        a new DOM Document the encrypted data.
        Throws:
        MessageProcessingException - if internal problems occurred generating the data.
      • encryptElement

        @Deprecated
        public org.w3c.dom.Document encryptElement​(org.w3c.dom.Document doc,
                                                   java.util.List<java.security.cert.X509Certificate> receipients,
                                                   boolean useKeyId)
                                            throws MessageProcessingException
        Deprecated.
        Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element. Uning default context
        Parameters:
        doc - the document to encrypt.
        receipients - a list of reciepiets of the message.
        useKeyId - if in key info should be included the shorter KeyName tag instead of X509Certificate
        Returns:
        a new DOM Document the encrypted data.
        Throws:
        MessageProcessingException - if internal problems occurred generating the data.
      • encryptElement

        public org.w3c.dom.Document encryptElement​(ContextMessageSecurityProvider.Context context,
                                                   org.w3c.dom.Document doc,
                                                   java.util.List<java.security.cert.X509Certificate> receipients,
                                                   boolean useKeyId)
                                            throws MessageProcessingException
        Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.
        Parameters:
        context - related security context.
        doc - the document to encrypt.
        receipients - a list of reciepiets of the message.
        useKeyId - if in key info should be included the shorter KeyName tag instead of X509Certificate
        Returns:
        a new DOM Document the encrypted data.
        Throws:
        MessageProcessingException - if internal problems occurred generating the data.
      • encryptElement

        public org.w3c.dom.Document encryptElement​(ContextMessageSecurityProvider.Context context,
                                                   org.w3c.dom.Document doc,
                                                   java.util.List<java.security.cert.X509Certificate> receipients,
                                                   XMLEncrypter.KeyInfoType keyInfoType)
                                            throws MessageProcessingException
        Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.
        Parameters:
        context - related security context.
        doc - the document to encrypt.
        receipients - a list of reciepiets of the message.
        keyInfoType - The type of keyinfo to add to the encrypted element.
        Returns:
        a new DOM Document the encrypted data.
        Throws:
        MessageProcessingException - if internal problems occurred generating the data.
      • decryptDocument

        @Deprecated
        public java.lang.Object decryptDocument​(org.w3c.dom.Document doc)
                                         throws MessageProcessingException,
                                                MessageContentException,
                                                NoDecryptionKeyFoundException
        Deprecated.
        Method to decrypt all encrypted structures in the related message. Using default context. Important: If multiple EncryptedData exists it must be encrypted with the same data key and receipients.
        Parameters:
        doc - the document containing encrypted data.
        Returns:
        a JAXB version of the document where all encrypted attributes are decrypted.
        Throws:
        MessageProcessingException - if internal problems occurred decrypting the message.
        MessageContentException - if content of message was invalid
        NoDecryptionKeyFoundException - if no related decryption key could be found with the message.
      • decryptDocument

        @Deprecated
        public java.lang.Object decryptDocument​(org.w3c.dom.Document doc,
                                                XMLEncrypter.DecryptedXMLConverter converter)
                                         throws MessageProcessingException,
                                                MessageContentException,
                                                NoDecryptionKeyFoundException
        Deprecated.
        Method to decrypt all encrypted structures in the related message. Using default context. Important: If multiple EncryptedData exists it must be encrypted with the same data key and receipients.
        Parameters:
        doc - the document containing encrypted data.
        converter - the post decryption xml converter to manipulate the result to fullfill schema, null to disable manipulation.
        Returns:
        a JAXB version of the document where all encrypted attributes are decrypted.
        Throws:
        MessageProcessingException - if internal problems occurred decrypting the message.
        MessageContentException - if content of message was invalid
        NoDecryptionKeyFoundException - if no related decryption key could be found with the message.
      • encryptProperties

        public org.w3c.dom.Document encryptProperties​(java.util.Properties properties,
                                                      java.util.List<java.security.cert.X509Certificate> receipients,
                                                      boolean useKeyId)
                                               throws MessageProcessingException
        Method to encrypt java.util.Properties in XML-format
        Parameters:
        properties - properties to encrypt
        receipients - a list of recipients of the properties.
        useKeyId - if in key info should be included the shorter KeyName tag instead of X509Certificate
        Returns:
        a new DOM Document with the encrypted properties.
        Throws:
        MessageProcessingException - if internal problems occurred encrypting the message.
      • generateKeyId

        public static java.lang.String generateKeyId​(java.security.PublicKey publicKey)
                                              throws MessageProcessingException
        Help method to generate a key id from a public key by calculating its SHA-256 Hash value and Base64 encoding it.
        Throws:
        MessageProcessingException