473,387 Members | 1,575 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,387 software developers and data experts.

Xml signature verification for X509Certificate

hi, I use the following function to compute the xml signature, (the
X509Certificate is imported from p12 format file, and saved in the system
store)

public void SignDocument(XmlDocument doc, AsymmetricAlgorithm key,
X509Certificate cert)
{
XmlNodeList list = doc.GetElementsByTagName("Signature");
if (list.Count > 0)
{
doc.RemoveChild(list[0]);
}

SignedXml sxml = new SignedXml(doc);

sxml.SigningKey = key;
sxml.SignedInfo.CanonicalizationMethod =
SignedXml.XmlDsigCanonicalizationUrl;

Reference r = new Reference("");
Transform trns = new XmlDsigC14NTransform();
r.AddTransform(trns);
XmlDsigEnvelopedSignatureTransform env = new
XmlDsigEnvelopedSignatureTransform();
r.AddTransform(env);

sxml.AddReference(r);

KeyInfo keyInfo = new KeyInfo();
// keyInfo.AddClause(new RSAKeyValue((RSA) key));
KeyInfoX509Data data = new KeyInfoX509Data(cert);
keyInfo.AddClause(data);
sxml.KeyInfo = keyInfo;

sxml.ComputeSignature();

XmlElement sig = sxml.GetXml();
doc.DocumentElement.AppendChild(doc.ImportNode(sig , true));
}
However, when I use the following function to verify the xml signature, it
always returns false, any one know why?

public bool CheckSignature(XmlDocument doc)
{
bool ret = false;
XmlNodeList list = doc.GetElementsByTagName("Signature");
if (list.Count > 0)
{
SignedXml sxml = new SignedXml(doc);
sxml.LoadXml((XmlElement) list[0]);

// AsymmetricAlgorithm key = null;
// bool use_public_key = sxml.CheckSignatureReturningKey(out key);

ret = sxml.CheckSignature();
}
return ret;
}

Anything I miss? Thank you!!
Apr 26 '06 #1
0 1556

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

Similar topics

2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
0
by: David Mediavilla | last post by:
I am trying to check a SOAP signature with WSE 1.0 SP1, but with a certain transform I only get an "Unknown tranform" exception. The SOAP signature is like this: <ds:Signature>...
1
by: borovA | last post by:
I am trying to access an Web. The problem is that they expect the client to submit a certificate. I can access the site from my browser, but it always asks which certificate I want to use. How...
6
by: Richard Loupatty | last post by:
Hi all, Does someone know what this mean: The check of the signature failed for assembly 'Infragistics.WebUI.UltraWebGrid.v2' I also did a post to Infragistics but maybe this is a general...
2
by: sudankanakavel | last post by:
i need a software which implement digital signature using algorithm:rsa,elgamal language:java os:windows software should compress,encrypt and sign data. decryption,certificate...
0
by: steven acer | last post by:
Hi i'm trying to sign a file and verify its signature with a DSA key. But i don't know if i'm doing it the right way !. I tried 2 different ways but i either got an error or simply the...
3
by: hdsingh71 | last post by:
We have two files, one is plain text another is signature file. We have to verify the integrity of the message. The details of SIG file is as under: Digital signature in PKCS7 format ...
9
stathread
by: stathread | last post by:
I am having an issue with the verification of a signature in C#. Everything below is in HEX. I have tried several different ways but all return false. The 2048 bit SHA1 RSA public key....
3
by: itcoll | last post by:
i have wriiten java code for client server communication - the client sends a digital signature and the server verifies it using the public key .I have sent the signature as a string from the client...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.