convert XML X.509Certificates
-
-
hi forum, I have made a signed XML document with MS Infopath 2003. Is possible to extract a X.509 Certificate from the XML document and import it to a CAPICOM.Certificate class or a System.Security.Cryptography.X509Certificate class? thanks in advance.
You can use the classes in the
System.Security.Cryptography.Xml
namespace to get theSignedXml.SigningKey
, which is anAsymmetricAlgorithm
. From that an other information you can reconstruct the X.509 certificate that contains the public key. While I don't cover this topic exactly, you might find some helpful hints in my article, Using XML Digital Signatures for Application Licensing[^]. Both this and the signatures used by InfoPath use the industry standard XML Digital Signature specification. You can find more information about that on the W3C[^] site as WS-Signature.Microsoft MVP, Visual C# My Articles
-
You can use the classes in the
System.Security.Cryptography.Xml
namespace to get theSignedXml.SigningKey
, which is anAsymmetricAlgorithm
. From that an other information you can reconstruct the X.509 certificate that contains the public key. While I don't cover this topic exactly, you might find some helpful hints in my article, Using XML Digital Signatures for Application Licensing[^]. Both this and the signatures used by InfoPath use the industry standard XML Digital Signature specification. You can find more information about that on the W3C[^] site as WS-Signature.Microsoft MVP, Visual C# My Articles
thank you, finally, i did this:
System.Xml.XmlNodeList nodeList = XmlDoc.GetElementsByTagName("X509Certificate"); // get the first certificate XmlNode node = (XMLNode)nodelist[0]; CAPICOM.Certificate certificates = new CAPICOM.CertificateClass() certificate.Import(node.InnerText);
..and it seems that works well :confused: -
thank you, finally, i did this:
System.Xml.XmlNodeList nodeList = XmlDoc.GetElementsByTagName("X509Certificate"); // get the first certificate XmlNode node = (XMLNode)nodelist[0]; CAPICOM.Certificate certificates = new CAPICOM.CertificateClass() certificate.Import(node.InnerText);
..and it seems that works well :confused:What are you confused about? The
InnerText
is the base64-encoded X.509 certificate, soImport
should have no problem reading it (as long as such a method accepts base64-encoded text, which that one obviously does). You should really try to avoid interop'ing the CryptoAPI, however. Most of the functionality you most likely need is already in the .NET Framework SDK. Mixing like this creates additional requirements, not to mentioning that marshaling data types from managed to unmanaged code can be very time consuming for certain types.Microsoft MVP, Visual C# My Articles
-
What are you confused about? The
InnerText
is the base64-encoded X.509 certificate, soImport
should have no problem reading it (as long as such a method accepts base64-encoded text, which that one obviously does). You should really try to avoid interop'ing the CryptoAPI, however. Most of the functionality you most likely need is already in the .NET Framework SDK. Mixing like this creates additional requirements, not to mentioning that marshaling data types from managed to unmanaged code can be very time consuming for certain types.Microsoft MVP, Visual C# My Articles