I need to sign some binary content (scanned documents) with a digital signature compliant with European norms, CAdES - XAdES. One option would be to use this library to do a XAdES signature. Is there a standard way of packaging binary content for inclusion in a XAdES enveloping signature? A developer in a hurry might Base64 encode the whole thing and put it in a pair of tags? Seems a bit savage. Is there an accepted way? What about canonicalization? Can I just turn it off?
Base64 will add huge overhead so I would suggest one of the following solutions:
- Sign the PDF but keep the XAdES signature in a separate XML file ("external signature"). The advantage is that the original document is instantly available even without the signature verification software. Which is also a security disadvantage, as people can open the file without verifying its authenticity. YMMV.
- Rather than embedding PDF inside XAdES, embed XAdES inside PDF, as the format is very well prepared already for digital signatures since ISO 32000 and there's even a dedicated PDF profile for that called PAdES. It's the best solution by all factors as the signature will be validated automatically on document opening and you don't need dedicated software. And usability was always a huge problem in EU electronic signature, as documented in this article.
There are three valid signature methods concerning european norms:
PAdES and XAdES refer specifically to a document format, PDF and XML.
PDF files signed with PAdES will remain PDF, and XML signed with XAdES will remain valid XML.
For every other file type, including binary content with no specific format, you should use CAdES. This will wrap your content in a P7M file that you will be able to inspect with P7M signature readers, and you will also be able to extract the original file if needed.
Encoding your content with Base64 and placing into an XML for XAdES signature is jumping through loops to reach your objective (having a signed file), and once you give that signed file to someone they will have no idea on how to interpret it, unless you also add instruction about how you encoded it, defeating the purpose of having a signature standard (as you manipulated your data in a non-standard way).
Base64 encoding the binary content was the way to go. The MS-XAdES package is the best, perhaps only, implementation of the European signature norms for dot net. Even with canonicalization, I had to serialize the XML on one line to get the signature to validate. XML, you have to love it.