Using JAXB with Signatures, Encryption, and Encryption

Recently, we were commissioned to develop an XML communication specification for our products. Some of my colleagues highly value JAXB for sorting and demonstrating XML documents. I spent some time playing with him, and I understand where they came from. This makes life easier for simple XML documents.

Now to take this place. One of the things that I would like to see in our communication model, β€œbuilt-in” to verify signatures for people who use it after me. One of the problems I am facing is that in order to verify the signature I need to process the corresponding XML as bytes. So let's look at this example ...

<topLevel> <sensitiveData encoding="UTF8"> <creditCard> <number>1234-1234-1234-1234</number> <expDate>Oct 2020</expDate> </creditCard> </sensitiveData> <signatureOfSensitiveData algorithm="SHA1WithRSA">VGhpc0lzQVNpZ25hdHVyZQ==</signatureOfSensitiveData> </topLevel> 

Edit: I do not transfer credit card details. Here is an example.

It would be great if I could get a byte[] representation (defined by the encoding) of everything inside the "sensitiveData" tag. I don't even mind to call "unmarshall" again on this byte[] .

It also opens other doors for us. In fact, we could introduce the compression and encryption attributes in the elements. If we could consider them as byte[] , we could then inflate and decrypt them, and then pass them on so that they are not there again.

Side note: I think this works if base64 encodes XML and then includes it in the element. But this forces us to base even simple documents and introduce some unnecessary bells and whistles into our messages.

Any ideas to solve this? I hope that I just missed something basic in JAXB and it will be a breeze after I get it.

Thanks!

+6
source share

Source: https://habr.com/ru/post/919531/


All Articles