Current location - Quotes Website - Signature design - How to sign with a certificate and verify a signed Xml object with Visual C#net
How to sign with a certificate and verify a signed Xml object with Visual C#net
To verify the document, you must use the asymmetric key used when signing. Create a CspParameters object and specify the name of the key container used for signing.

CSP parameters CSP parameters = new CSP parameters();

C program KEY container name = " XML _ DSIG _ RSA _ KEY ";

Use the RSACryptoServiceProvider class to retrieve the public key. When you pass the CspParameters object to the constructor of the RSACryptoServiceProvider class, the key is automatically loaded from the key container by name.

Rsacryptoserviceprovider rsakey = new rsacrytoserviceprovider (CSP params);

Load an XML file from disk to create an XmlDocument object. The XmlDocument object contains the signed XML document to verify.

XML document XML doc = new XML document();

//load the XML file into the XmlDocument object.

xmlDoc。 PreserveWhitespace = true

xmlDoc。 load(" test . XML ");