By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,994 Members | 1,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,994 IT Pros & Developers. It's quick & easy.

Addition of Keyname in the xml signature

P: n/a
Hi all ,
Can anyone help me out in finding a way to add the "keyname' tag in the
keyinfo of the xml signature
the sample code here adds the DSA/RSA Keyvalue tag in the keyinfo.

// Create example data to sign.
DSA objDSAkey = DSA.Create();
string strDSAKeyXML = objDSAkey.ToXmlString(true);
XmlDocument objXMLdocument = new XmlDocument();
objXMLdocument.LoadXml(strDSAKeyXML);
objXMLdocument.Save("XMLSignatureDSAKeyPair.xml");

// Save only the PublicKey.
strDSAKeyXML = objDSAkey.ToXmlString(false);
objXMLdocument = new XmlDocument();
objXMLdocument.LoadXml(strDSAKeyXML);
objXMLdocument.Save("XMLSignatureDSAPublicKey.xml" );

XmlDocument objDSAKeyPairXMLdocument = new XmlDocument();
objDSAKeyPairXMLdocument.Load("XMLSignatureDSAKeyP air.xml");
string strDSAKeyPairXML = objDSAKeyPairXMLdocument.InnerXml;
SignedXml signedXml = new SignedXml();
DSA objDSAkeyPair = DSA.Create();
objDSAkeyPair.FromXmlString(strDSAKeyPairXML );
signedXml.SigningKey = objDSAkeyPair ;
// The above sets the KeyPair used to Sign

XmlDocument objdocument = new XmlDocument();
objdocument.Load("CreditCardInfo.xml");

DataObject dataObject = new DataObject();
dataObject.Data = objdocument.ChildNodes;
dataObject.Id = "CreditCardInfo";

signedXml.AddObject(dataObject);

Reference reference = new Reference();
reference.Uri = "#CreditCardInfo";

signedXml.AddReference(reference);

//This is optional. KeyInfo need not be transmitted along with
signedXML
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new DSAKeyValue(objDSAkeyPair));
signedXml.KeyInfo = keyInfo;

Generated XML contains ...

<KeyInfo>
<KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
<DSAKeyValue>
<P>rJG9SxL0vbiMuv71LO93CQcwed+64wuOe7S8Ld9l7dPakgB dq7qDLQd52W5R08LDR9OYW5+hjTSQwu7FJbkusVpxcNAeQgBej Sg0bN9Pl/AvrXTn182RRbQxf//odSGMk4MabK4oryY596uV0FiqWG9gNHn4qWiHPYYPBqK1yVU=</P>
<Q>5NQ0E14Y7SQTH7DN4aJKU1dU29E=</Q>
<G>I3k7Ya3tzQdivS0mORJUwhu48xUQlDNhsINbvaeFOlb4Aqu mDSCmFz3urueV6RVg2MrpllTll7biGeBuOwgrPDj8
uyVrjqIuUYNaubLrrcM6xwCuzUxjUKjMnS4QPtVW9+CL54b2DA Szfg/wsEiu+sNZCMfsT79N1u4FbGlRVZI=</G>
<Y>LKu08/Jx7o4Vyw1eru+ShPw74yd/zqRV4r
LNeGxWhazdudzIjYdRIOu3TkzdM4j+FlPQo80a6Y06lXCB+9RE hDuogeYSQc6la40sFeCIraDGhq1ubPcyqGiVX4dbJxoTyQxI61 l6cdFjLT/qRvHpVrqG69Bex3W
nQl1lMup1ICs=</Y>
<J>wQ9kPQEXFRMsMADCxM3wFdnwN1goipvS8nHnzSrRoyRtYtD vWRHsWZtsVtfK/zg0R1OJsMrsZC0xsAsfvhy6EhJzRD1qcr09JQcqkfpnM
WDkLDk9o2p64xvAJG0iyuc1CkkWBcUC9z8L+w0U</J>
<Seed>C1rYOMKlGngpNIzkDfs/odRTKyA=</Seed>
<PgenCounter>bw==</PgenCounter>
</DSAKeyValue>
</KeyValue>
</KeyInfo>

but i need it this way

<KeyInfo>
<KeyName>mykeyname</KeyName>
</KeyInfo>

Is it is possible to add/generate xmlsignature with the keyname ?
Please help

Mar 31 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.