public void TestVerifySignatureFailure2() { //First sign sm = new SignatureManager(); XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); XmlNamespaceManager nsMgr = new XmlNamespaceManager(signed.OwnerDocument.NameTable); nsMgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); //get the Digest value XmlNode digValueNode = signed.SelectSingleNode("ds:SignedInfo/ds:Reference/ds:DigestValue", nsMgr); string digest = digValueNode.InnerXml; //Tamper it. digest = digest.ToUpper(); signed.SelectSingleNode("ds:SignedInfo/ds:Reference/ds:DigestValue", nsMgr).InnerXml = digest; //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters DSAParameters verificationDSAParams = dsa.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify sm.VerifySignature(signed, keyInfoProvider); }
public void TestVerifySignatureFailure1() { //First sign sm = new SignatureManager(); XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //get the SignatureValue XmlNode sigValueNode = signed.SelectSingleNode("SignatureValue"); string signature = sigValueNode.InnerXml; //Tamper it. signature = signature.ToUpper(); signed.SelectSingleNode("SignatureValue").InnerXml = signature; //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters DSAParameters verificationDSAParams = dsa.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify sm.VerifySignature(signed, keyInfoProvider); }
public void TheDemo() { //Setup References IList <InstantiationVO> transformersList1 = new List <InstantiationVO>(); InstantiationVO digester1 = new InstantiationVO("http://www.w3.org/2000/09/xmldsig#sha1", new Dictionary <string, object>()); IReference reference1 = new Reference("http://www.google.com", transformersList1, digester1, "http"); IList <IReference> references = new List <IReference>(); references.Add(reference1); //Setup Canonicalizer IDictionary <string, object> c14nParams = new Dictionary <string, object>(); InstantiationVO c14nIVO = new InstantiationVO("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", c14nParams); //Setup Signers DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); DSAParameters dsaParams = dsa.ExportParameters(true); IDictionary <string, object> signerParams = new Dictionary <string, object>(); signerParams.Add("DSAKeyInfo", dsaParams); InstantiationVO signerIVO = new InstantiationVO("xml:dig:signer:rsa-dsa", signerParams); //Setup main digester InstantiationVO digesterMain = new InstantiationVO("http://www.w3.org/2000/09/xmldsig#sha1", new Dictionary <string, object>()); SignatureManager sm = new SignatureManager(); //Sign the references XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters DSAParameters verificationDSAParams = dsa.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify sm.VerifySignature(signed, keyInfoProvider); }
public void TestVerifySignature() { //First sign sm = new SignatureManager(SHA256Namespace); XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters DSAParameters verificationDSAParams = dsa.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify. Note that if no exception is thrown here then verification was successful. //No assert would be required. sm.VerifySignature(signed, keyInfoProvider); }
public void TestVerifySignatureFailure3() { //First sign sm = new SignatureManager(); XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters //Note that new instance of DSACryptoServiceProvider creates a different public key than //the one that was used for signing DSACryptoServiceProvider dsa1 = new DSACryptoServiceProvider(); DSAParameters verificationDSAParams = dsa1.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify sm.VerifySignature(signed, keyInfoProvider); }