EDN Admin
Well-known member
<div style="color:black; background-color:white
<pre>Below is the code for signing the XML , here i need to add the reference like
Reference = "#Resource1"
When i add as reference.uri -="#Resource1" it says Malformed reference element.
When i add as reference.id ="#Resource1" it says The input type was invalid for this transform
How can i get Reference = "#Resource1"
[/code]
<pre style="color:black <span style="color:green // Check arguments.[/code]
<div style="color:black; background-color:white
<pre> <span style="color:blue if (xmlDoc == <span style="color:blue null)
<span style="color:blue throw <span style="color:blue new ArgumentException(<span style="color:#a31515 "xmlDoc");
<span style="color:blue if (Key == <span style="color:blue null)
<span style="color:blue throw <span style="color:blue new ArgumentException(<span style="color:#a31515 "Key");
<span style="color:green // Create a SignedXml object.
SignedXml signedXml = <span style="color:blue new SignedXml(xmlDoc);
<span style="color:green // Add the key to the SignedXml document.
signedXml.SigningKey = Key;
<span style="color:green // Create a reference to be signed.
<span style="color:green //string resourceToSign = "www.Resource1.com";
Reference reference = <span style="color:blue new Reference();
reference.Id = <span style="color:#a31515 "2";
<span style="color:green // Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = <span style="color:blue new XmlDsigEnvelopedSignatureTransform();
<span style="color:green // reference.AddTransform(env);
<span style="color:green // Add the reference to the SignedXml object.
signedXml.AddReference(reference);
X509Certificate2 certificate = <span style="color:blue new X509Certificate2(<span style="color:#a31515 @"C:ABC_b64.cer");
KeyInfo keyInfo = <span style="color:blue new KeyInfo();
X509Chain x509Chain = <span style="color:blue new X509Chain();
x509Chain.Build(certificate);
<span style="color:blue foreach (X509ChainElement element <span style="color:blue in x509Chain.ChainElements)
{
KeyInfoX509Data x509Data = <span style="color:blue new KeyInfoX509Data(element.Certificate);
<span style="color:blue string issuer = element.Certificate.Issuer;
<span style="color:blue string subjectName = element.Certificate.SubjectName.Name;
x509Data.AddSubjectName(subjectName);
}
signedXml.KeyInfo = keyInfo;
<span style="color:green // Compute the signature.
signedXml.ComputeSignature();
[/code]
<br/>
<
Regards Suresh<br/>
<br/>
View the full article
<pre>Below is the code for signing the XML , here i need to add the reference like
Reference = "#Resource1"
When i add as reference.uri -="#Resource1" it says Malformed reference element.
When i add as reference.id ="#Resource1" it says The input type was invalid for this transform
How can i get Reference = "#Resource1"
[/code]
<pre style="color:black <span style="color:green // Check arguments.[/code]
<div style="color:black; background-color:white
<pre> <span style="color:blue if (xmlDoc == <span style="color:blue null)
<span style="color:blue throw <span style="color:blue new ArgumentException(<span style="color:#a31515 "xmlDoc");
<span style="color:blue if (Key == <span style="color:blue null)
<span style="color:blue throw <span style="color:blue new ArgumentException(<span style="color:#a31515 "Key");
<span style="color:green // Create a SignedXml object.
SignedXml signedXml = <span style="color:blue new SignedXml(xmlDoc);
<span style="color:green // Add the key to the SignedXml document.
signedXml.SigningKey = Key;
<span style="color:green // Create a reference to be signed.
<span style="color:green //string resourceToSign = "www.Resource1.com";
Reference reference = <span style="color:blue new Reference();
reference.Id = <span style="color:#a31515 "2";
<span style="color:green // Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = <span style="color:blue new XmlDsigEnvelopedSignatureTransform();
<span style="color:green // reference.AddTransform(env);
<span style="color:green // Add the reference to the SignedXml object.
signedXml.AddReference(reference);
X509Certificate2 certificate = <span style="color:blue new X509Certificate2(<span style="color:#a31515 @"C:ABC_b64.cer");
KeyInfo keyInfo = <span style="color:blue new KeyInfo();
X509Chain x509Chain = <span style="color:blue new X509Chain();
x509Chain.Build(certificate);
<span style="color:blue foreach (X509ChainElement element <span style="color:blue in x509Chain.ChainElements)
{
KeyInfoX509Data x509Data = <span style="color:blue new KeyInfoX509Data(element.Certificate);
<span style="color:blue string issuer = element.Certificate.Issuer;
<span style="color:blue string subjectName = element.Certificate.SubjectName.Name;
x509Data.AddSubjectName(subjectName);
}
signedXml.KeyInfo = keyInfo;
<span style="color:green // Compute the signature.
signedXml.ComputeSignature();
[/code]
<br/>
<
Regards Suresh<br/>
<br/>
View the full article