473,786 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Signi ngKey = 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
XmlDsigEnvelope dSignatureTrans form env = new
XmlDsigEnvelope dSignatureTrans form();
reference.AddTr ansform(env);

// Add the reference to the SignedXml object
signedXml.AddRe ference(referen ce);
}

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

// Add an enveloped transformation to the reference
XmlDsigEnvelope dSignatureTrans form env2 = new
XmlDsigEnvelope dSignatureTrans form();
reference2.AddT ransform(env2);

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

// Compute the signature
signedXml.Compu teSignature();

// Get the XML representation of the signature and save it to an
XmlElement object
XmlElement xmlDigitalSigna ture = signedXml.GetXm l();

// Append the element to the XML document
Doc.DocumentEle ment.AppendChil d(Doc.ImportNod e(xmlDigitalSig nature,
true));
Many thanks,

AK
Nov 11 '08 #1
1 3902
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
XmlDsigEnvelope dSignatureTrans form env = new
XmlDsigEnvelope dSignatureTrans form();
reference.AddTr ansform(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
6520
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 delta binary is pretty huge in size. I have 1 byte file and 2 bytes file, the delta should be 1 byte but somehow it turns out to be 249 bytes using binary formatter. I guess serialization has some other things added to the delta file.
8
5127
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
3666
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 binary mode. according to me, notepad opens files and each byte of the file read, it converts that byte from ascii to its correct character and displays
68
5261
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
3
18962
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 original form. The problem is tha the binary source that I extract from the text file seems to be diferent from the source I saved. Here is my code: 1) handle=file('image.gif','rb')
15
3004
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 successfully created and used txt files. I am trying to save then load in an array of pointers to objects:
2
1520
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 below. The data comes in 40 byte packets via stdin or a binary file. my_Data_pkt(){ syncByte (8bits) XML_type (2bits) XML_subtype (2bits) record_value (3bits)
4
9174
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?) and must be digitally signed. Is out there some kind of libraries to ease this tasks? * Access to the local user certificate store, and read PEM or PKCS12 certificate files. * Read, parse and validate user certificates
10
1997
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 which I can later copy and past into a python program. I will eventually expand the program to also output an SQL script to create a SQL file in MySQL The program still need a little work, it does not handle the following items
0
9491
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.