473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

newbie question - how to sign binary files

AK
Hello,

I'm trying to create an XML digital signature over some assets listed
in the XML file. It works fine until I add a pdf file in the list of
assets, which throws an exception saying that "Data at the root level
is invalid". I'm sure it must be possible to sign binary files as
well, but I've been searching for hours and can't find any examples.
Hope someone can help me with this.

Here's the code I'm using:

// Create a SignedXml object
SignedXml signedXml = new SignedXml(Doc);

// Add the key
signedXml.SigningKey = Key;

// Get urls to assets with signed = true
assetUris = getAssetUris();

foreach (string assetUri in assetUris)
{
// Create a reference to be signed
Reference reference = new Reference();
reference.Uri = assetUri;

// Add an enveloped transformation to the reference
XmlDsigEnvelopedSignatureTransform env = new
XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);

// Add the reference to the SignedXml object
signedXml.AddReference(reference);
}

// Hash the entire doc as well so that the asset description will be
hashed
Reference reference2 = new Reference();
reference2.Uri = "";
signedXml.AddReference(reference2);

// Add an enveloped transformation to the reference
XmlDsigEnvelopedSignatureTransform env2 = new
XmlDsigEnvelopedSignatureTransform();
reference2.AddTransform(env2);

// Add the KeyInfo object holding the certificate into the SignedXml
object
signedXml.KeyInfo = getKeyInfo();

// Compute the signature
signedXml.ComputeSignature();

// Get the XML representation of the signature and save it to an
XmlElement object
XmlElement xmlDigitalSignature = signedXml.GetXml();

// Append the element to the XML document
Doc.DocumentElement.AppendChild(Doc.ImportNode(xml DigitalSignature,
true));
Many thanks,

AK
Nov 11 '08 #1
1 3882
AK
And as usual, I'll answer myself in case anyone else might have the
same problem in the future. With a little help from a friend, I
realised that I was trying to apply the transform to the binary files,
which obviously fails.

So, for the binary files, don't do the following:

// Add an enveloped transformation to the reference
XmlDsigEnvelopedSignatureTransform env = new
XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);

Cheers,

AK
Nov 11 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
8
by: dagecko | last post by:
Hi I would like to know how to detect if a file is binary or not. It's important for me but I don't know where to start. Ty
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
15
by: JoeC | last post by:
I am writing a program that I am trying to learn and save binary files. This is the page I found as a source: http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html I have...
2
by: Damfino | last post by:
Hi all, Newbie question here wrt defining a class that will work on bits read from a binary file. How would you go about doing it? As an example please look at the structure of my data given...
4
by: haxier | last post by:
Hi all I'm developing an application with some reports and we're looking for advice. This reports should be openoffice.org .odf files, pdf files, and perhaps microsoft word files (.doc, .docx?)...
10
by: len | last post by:
I have created the following program to read a text file which happens to be a cobol filed definition. The program then outputs to a file what is essentially a file which is a list definition...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.