Is it possible to sign resources pointed to from an xml doc and the
element that contains those urls at the same time?
This is the xml:
<osfm:assets name="">
<osfm:asset media-type="text/xml" name="META-INF/
Container.xml" />
<osfm:asset media-type="text/xml" name="META-INF/Manifest.xml" /
><osfm:asset media-type="text/xml" name="META-INF/Metadata.xml" /
></osfm:assets>
So, after hashing those three files I would also like to hash the
osfm:assets element, but I can't find a way to do that without
creating a new SignedXml object, which then means I've got two
signatures. Does anyone know if I can add the element here as well?
This is the code so far:
public void hashAssets(XmlDocument Doc, RSA Key)
{
// 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);
}
// This is where I would like to hash the xml element
XmlElement assetElement = Doc.GetElementsByTagName("osfm:assets")[0]
as XmlElement;
// 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,
Annelie