public void Test(SignedXmlDocument doc) { Console.WriteLine("================== Certificate Test =================="); var certVipNet = doc.CertificateValue.Value; var result = doc.CertificateValue.Value == Convert.ToBase64String(Certificate.GetRawCertData()); Console.WriteLine("Test done: {0}", result); Console.WriteLine("======================================================"); Console.WriteLine("================ Canonicalization Test ================"); var doc2 = doc.Document.GetXmlDocument(); XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform(); var bodyNode = doc.Body.GetXmlNode(); t.LoadInput(bodyNode); Stream canonicalXmlStream = (MemoryStream)t.GetOutput(typeof(Stream)); var canonicalXml = new StreamReader(canonicalXmlStream).ReadToEnd(); var t2 = new XmlDsigC14NTransform(); t2.LoadInput(doc.Body.GetXmlNode()); Stream canonicalXmlStream2 = (MemoryStream)t2.GetOutput(typeof(Stream)); var canonicalXml2 = new StreamReader(canonicalXmlStream2).ReadToEnd(); Console.WriteLine(canonicalXml == canonicalXml2); Console.WriteLine(canonicalXml); Console.WriteLine("======================================================"); var signedXml = new SignedXml(doc2); var reference = new Reference("#body"); reference.AddTransform(new XmlDsigExcC14NTransform()); signedXml.AddReference(reference); Hash hash = new VipNetCrytoProvider().HashData(canonicalXml); Console.WriteLine(hash.Base64); Console.WriteLine(hash.Hex); Console.WriteLine("CorrectHashExample: {0}", CorrectHashExample); Console.WriteLine("CorrectHashExampleHex: {0}", Convert.FromBase64String(CorrectHashExample).ByteArrayToString()); }
public void Run() { var testDoc = new SignedXmlDocument(DocWithoutSignature); testDoc = new SignedXmlDocument(testDoc.ToString()); var testDoc2 = new SignedXmlDocument(testDoc.ToString()); var testDoc3 = new SignedXmlDocument(testDoc2.ToString()); var testDoc4 = new SignedXmlDocument(testDoc3.ToString()); var testDoc5 = new SignedXmlDocument(testDoc4.ToString()); var provider = new VipNetCrytoProvider(); TestSignature.Test(provider); //return; //TestSignedXmlPrefix(); using (var output = File.CreateText("output.txt")) { provider.SignDocument(testDoc); Console.WriteLine(testDoc.Document); output.WriteLine(testDoc.ToString()); } var verify = SignatureVerifier.Verify(testDoc.ToString(), provider); var testCertificate = new TestCertificate(); testCertificate.Test(testDoc); var doc = new XmlDocument(); doc.LoadXml(DocWithoutSignature); new SignedXmlDoc(DocWithoutSignature); }
public void StandartSigning(SignedXmlDocument doc) { var signedXml = new SignedXml(doc.Document.GetXmlDocument()); //signedXml.AddReference(new Reference("#CertId").AddTransform(new XmlDsigExcC14NTransform())); }