Hi,
I have a Clickonce application that contains a file element:
<file name="Properties\Resources\wecan32.ico" size="3262">
<hash>
<dsig:Transforms>
<dsig:Transform
Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>hKQC+HwduEy3n7PERz4GD3tPgME=</dsig:DigestValue>
</hash>
</file>
I've coded a routine that tries to duplicate the above XmlNode:
void FormFileAssociationCreator_IconFileElementEvent(object sender,
ResultsEventArgs e)
{
Cursor = Cursors.WaitCursor;
buildOutput.AppendLine(Resources.CreatingIconElement);
XmlDocument applicationManifestDoc = new XmlDocument();
try
{
textBoxOutput.Text =
buildOutput.AppendLine(Resources.AddingIconFileElement).ToString();
applicationManifestDoc.Load(comboBoxApplicationManifest.Text);
XmlNamespaceManager namespaceManager;
namespaceManager = new XmlNamespaceManager(new NameTable());
namespaceManager.AddNamespace("asmv1",
"urn:schemas-microsoft-com:asm.v1");
namespaceManager.AddNamespace("asmv2",
"urn:schemas-microsoft-com:asm.v2");
XmlNode applicationNode =
applicationManifestDoc.SelectSingleNode("/asmv1:assembly/asmv2:application",
namespaceManager);
//create the icon node and add it following the application
node
XmlNode iconNode = CreateIconElement(applicationManifestDoc);
applicationNode.ParentNode.InsertAfter(iconNode,
applicationNode);
XmlNode hashNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, "hash", null);
iconNode.AppendChild(hashNode);
XmlNode transformsNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:Transforms",
null);
hashNode.AppendChild(transformsNode);
XmlNode transformNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:Transform",
null);
XmlNode transformAlgorithmAttrib =
applicationManifestDoc.CreateNode(XmlNodeType.Attribute, "Algorithm", null);
transformAlgorithmAttrib.Value =
"urn:schemas-microsoft-com:HashTransforms.Identity";
transformNode.Attributes.SetNamedItem(transformAlgorithmAttrib);
transformsNode.AppendChild(transformNode);
XmlNode digestMethodNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:DigestMethod",
null);
XmlNode digestMethodAttrib =
applicationManifestDoc.CreateNode(XmlNodeType.Attribute, "Algorithm", null);
digestMethodAttrib.Value =
"http://www.w3.org/2000/09/xmldsig#sha1";
digestMethodNode.Attributes.SetNamedItem(digestMethodAttrib);
hashNode.AppendChild(digestMethodNode);
XmlNode digestValueNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:DigestValue",
null);
hashNode.AppendChild(digestValueNode);
XmlNode digestValueTextNode =
applicationManifestDoc.CreateNode(XmlNodeType.Text, @"dsig:DigestValue",
null);
hashNode.AppendChild(digestValueTextNode);
FileInfo iconFileInfo = new
FileInfo(comboBoxIconFile.SelectedItem.ToString());
Stream iconStream = iconFileInfo.OpenRead();
SHA1Managed iconHash = new SHA1Managed();
byte[] iconHashBytes = iconHash.ComputeHash(iconStream);
digestValueTextNode.Value =
Convert.ToBase64String(iconHashBytes);
applicationManifestDoc.Save(comboBoxApplicationManifest.Text);
textBoxOutput.Text =
buildOutput.AppendLine(Resources.AddedIconFileElement).ToString();
}
My out put is nearly whats expected except absent is the dsig: prefix on the
hash elements nodes:
<file name="\Properties\Resources\wecan32.ico" size="3262" xmlns="">
<hash>
<Transforms>
<Transform
Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue />hKQC+HwduEy3n7PERz4GD3tPgME=
</hash>
</file>
So my question is how can my impementation be changed so dsig: prefix is
added?

Signature
Kenneth Lemieux
Project Engineer
Whelen Engineering Co., Inc.
Martin Honnen - 03 Mar 2008 17:30 GMT
> I have a Clickonce application that contains a file element:
>
[quoted text clipped - 8 lines]
> </hash>
> </file>
That is an excerpt from an XML document, you need to check which
namespace URI the prefix dsig is bound to on the ancestor(s) of the
dsig:Transform element. Use that namespace URI to create elements in
that namespace e.g. assuming the namespace URI is
http://example.com/dsig then you need
> XmlNode transformsNode =
> applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:Transforms",
> null);
const string dsig = "http://example.com/dsig";
XmlElement transforms = applicationManifestDoc.CreateElement("dsig",
"Transforms", dsig);
> hashNode.AppendChild(transformsNode);
> XmlNode transformNode =
> applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:Transform",
> null);
Same here
XmlElement transforms = applicationManifestDoc.CreateElement("dsig",
"Transform", dsig);
Then apply the same changes to the other elements you need to create in
that namespace.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Ken Lemieux - 03 Mar 2008 21:03 GMT
Thanks Martin, your post answered my question perfectly.
One more question if I may, Could and would you recommend a comprehensive
book on Xml. I'm particular intrested in securing the xml data and its
applications.
Thanks again.

Signature
Kenneth Lemieux
Project Engineer
Whelen Engineering Co., Inc.
> > I have a Clickonce application that contains a file element:
> >
[quoted text clipped - 34 lines]
> Then apply the same changes to the other elements you need to create in
> that namespace.