Class XMLEncrypter
- java.lang.Object
-
- org.certificateservices.messages.utils.XMLEncrypter
-
public class XMLEncrypter extends java.lang.ObjectHelper methods to perform XML Encryption and Decryption tasks on JAXB Elements.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceXMLEncrypter.DecryptedXMLConverterInterface to do post decryption manipulation to the DOM to have the decrypted document to fullfill it schema.static classXMLEncrypter.KeyInfoTypeEnumeration of supported KeyInfoTypes
-
Constructor Summary
Constructors Constructor Description XMLEncrypter(MessageSecurityProvider securityProvider, javax.xml.parsers.DocumentBuilder documentBuilder, javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller)Contsructor of a xml XML Encrypter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description org.w3c.dom.DocumentdecryptDoc(ContextMessageSecurityProvider.Context context, org.w3c.dom.Document doc, XMLEncrypter.DecryptedXMLConverter converter)Method to decrypt all encrypted structures in the related message.org.w3c.dom.DocumentdecryptDoc(org.w3c.dom.Document doc, XMLEncrypter.DecryptedXMLConverter converter)Method to decrypt all encrypted structures in the related message, using default context.java.lang.ObjectdecryptDocument(ContextMessageSecurityProvider.Context context, org.w3c.dom.Document doc)Method to decrypt all encrypted structures in the related message.java.lang.ObjectdecryptDocument(ContextMessageSecurityProvider.Context context, org.w3c.dom.Document doc, XMLEncrypter.DecryptedXMLConverter converter)Method to decrypt all encrypted structures in the related message.java.lang.ObjectdecryptDocument(org.w3c.dom.Document doc)Deprecated.java.lang.ObjectdecryptDocument(org.w3c.dom.Document doc, XMLEncrypter.DecryptedXMLConverter converter)Deprecated.java.util.PropertiesdecryptProperties(org.w3c.dom.Document encDocument)Method to decrypt document containing properties in XML-format.org.w3c.dom.DocumentencryptElement(javax.xml.bind.JAXBElement<?> element, java.util.List<java.security.cert.X509Certificate> receipients, boolean useKeyId)Deprecated.org.w3c.dom.DocumentencryptElement(ContextMessageSecurityProvider.Context context, javax.xml.bind.JAXBElement<?> element, java.util.List<java.security.cert.X509Certificate> receipients, boolean useKeyId)Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.org.w3c.dom.DocumentencryptElement(ContextMessageSecurityProvider.Context context, javax.xml.bind.JAXBElement<?> element, java.util.List<java.security.cert.X509Certificate> receipients, XMLEncrypter.KeyInfoType keyInfoType)Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.org.w3c.dom.DocumentencryptElement(ContextMessageSecurityProvider.Context context, org.w3c.dom.Document doc, java.util.List<java.security.cert.X509Certificate> receipients, boolean useKeyId)Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.org.w3c.dom.DocumentencryptElement(ContextMessageSecurityProvider.Context context, org.w3c.dom.Document doc, java.util.List<java.security.cert.X509Certificate> receipients, XMLEncrypter.KeyInfoType keyInfoType)Method to create a encrypted DOM structure containing a EncryptedData element of the related JAXB Element.org.w3c.dom.DocumentencryptElement(org.w3c.dom.Document doc, java.util.List<java.security.cert.X509Certificate> receipients, boolean useKeyId)Deprecated.org.w3c.dom.DocumentencryptProperties(java.util.Properties properties, java.util.List<java.security.cert.X509Certificate> receipients, boolean useKeyId)Method to encrypt java.util.Properties in XML-formatstatic java.lang.StringgenerateKeyId(java.security.PublicKey publicKey)Help method to generate a key id from a public key by calculating its SHA-256 Hash value and Base64 encoding it.
-
-
-
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 providerdocumentBuilder- 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 MessageProcessingExceptionDeprecated.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 useelement- 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 useelement- 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 MessageProcessingExceptionDeprecated.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, NoDecryptionKeyFoundExceptionDeprecated.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 invalidNoDecryptionKeyFoundException- if no related decryption key could be found with the message.
-
decryptDocument
public java.lang.Object decryptDocument(ContextMessageSecurityProvider.Context context, org.w3c.dom.Document doc) throws MessageProcessingException, MessageContentException, NoDecryptionKeyFoundException
Method to decrypt all encrypted structures in the related message. Important: If multiple EncryptedData exists it must be encrypted with the same data key and receipients.- Parameters:
context- the message security context to use.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 invalidNoDecryptionKeyFoundException- 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, NoDecryptionKeyFoundExceptionDeprecated.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 invalidNoDecryptionKeyFoundException- if no related decryption key could be found with the message.
-
decryptDocument
public java.lang.Object decryptDocument(ContextMessageSecurityProvider.Context context, org.w3c.dom.Document doc, XMLEncrypter.DecryptedXMLConverter converter) throws MessageProcessingException, MessageContentException, NoDecryptionKeyFoundException
Method to decrypt all encrypted structures in the related message. Important: If multiple EncryptedData exists it must be encrypted with the same data key and receipients.- Parameters:
context- the message security context to use.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 invalidNoDecryptionKeyFoundException- if no related decryption key could be found with the message.
-
decryptDoc
public org.w3c.dom.Document decryptDoc(org.w3c.dom.Document doc, XMLEncrypter.DecryptedXMLConverter converter) throws MessageProcessingException, MessageContentException, NoDecryptionKeyFoundExceptionMethod 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 new Document with decrypted content.
- Throws:
MessageProcessingException- if internal problems occurred decrypting the message.MessageContentException- if content of message was invalidNoDecryptionKeyFoundException- if no related decryption key could be found with the message.
-
decryptDoc
public org.w3c.dom.Document decryptDoc(ContextMessageSecurityProvider.Context context, org.w3c.dom.Document doc, XMLEncrypter.DecryptedXMLConverter converter) throws MessageProcessingException, MessageContentException, NoDecryptionKeyFoundException
Method to decrypt all encrypted structures in the related message. Important: If multiple EncryptedData exists it must be encrypted with the same data key and receipients.- Parameters:
context- the message security context to use with the security provider.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 new Document with decrypted content.
- Throws:
MessageProcessingException- if internal problems occurred decrypting the message.MessageContentException- if content of message was invalidNoDecryptionKeyFoundException- 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 MessageProcessingExceptionMethod to encrypt java.util.Properties in XML-format- Parameters:
properties- properties to encryptreceipients- 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.
-
decryptProperties
public java.util.Properties decryptProperties(org.w3c.dom.Document encDocument) throws NoDecryptionKeyFoundException, MessageProcessingException, MessageContentExceptionMethod to decrypt document containing properties in XML-format.- Parameters:
encDocument- the document containing encrypted data.- Returns:
- decrypted properties
- Throws:
NoDecryptionKeyFoundException- if no related decryption key could be found.MessageProcessingException- if internal problems occurred decrypting the message.MessageContentException- if content of document was invalid
-
generateKeyId
public static java.lang.String generateKeyId(java.security.PublicKey publicKey) throws MessageProcessingExceptionHelp method to generate a key id from a public key by calculating its SHA-256 Hash value and Base64 encoding it.- Throws:
MessageProcessingException
-
-