Exemple #1
0
        public void SignDocument(SignedXmlDocument document)
        {
            //String testBody = "<soapenv:Body wsu:Id=\"body\"><typ:ChangeOrderStatusV243Request><smev:Message><smev:Sender><smev:Code>EPGU_SYS_1</smev:Code><smev:Name>ЕПГУ</smev:Name></smev:Sender><smev:Recipient><smev:Code>MINPROM_SYS_1</smev:Code><smev:Name>Минпромторг России</smev:Name></smev:Recipient><smev:Originator><smev:Code>EPGU_SYS_1</smev:Code><smev:Name>ЕПГУ</smev:Name></smev:Originator><smev:TypeCode>GSRV</smev:TypeCode><smev:Status>REQUEST</smev:Status><smev:Date>2012-06-05T17:14:19+04:00</smev:Date><smev:ExchangeType>1</smev:ExchangeType><smev:ServiceCode>10001014881</smev:ServiceCode></smev:Message><smev:MessageData><smev:AppData wsu:Id=\"AppData\"><chan:changeOrderInfo><chan:serviceInfo><chan:serviceOrgCode>MPT0</chan:serviceOrgCode><chan:eServiceId/><chan:reestrId>10001014881</chan:reestrId></chan:serviceInfo><chan:orderId><chan:pguId>7d6476ac-a728-4863-804e-a5789d29c630</chan:pguId><chan:orgId/></chan:orderId><chan:statusCode><chan:orgCode/><chan:techCode>2</chan:techCode></chan:statusCode><chan:comment>Заявление отправлено в ведомство</chan:comment><chan:cancelAllowed>false</chan:cancelAllowed><chan:authToken>TEST_TOKEN_1</chan:authToken></chan:changeOrderInfo><smev:error><smev:errorCode/><smev:errorMessage/></smev:error></smev:AppData><smev:AppDocument><smev:RequestCode>req_7d6476ac-a728-4863-804e-a5789d29c630</smev:RequestCode><smev:BinaryData>UEsDBBQACAAIAHZ6r0AAAAAAAAAAAAAAAAAsABAAcmVxXzdkNjQ3NmFjLWE3MjgtNDg2My04MDRlLWE1Nzg5ZDI5YzYzMC54bWxVWAwAVjyyT887sk/1ARQAZY/JDoJADIbP8hSGq9GRGJTDMMSNgxqN4JJ4Y2kIyswgDAZ9emeIMS6Xpv/X9m+LnZpm7RsUZcqZrRu9vt4GFvE4ZYmt73du19IdouFxnmcpxDMeVRSYKIn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czYn10SXPy0tJCkpnDbn/Po7HRG9Qn9HnxewPFiY5XfZ55i9lCH/vNA5PksrPmQ7Kdaz1vEJUiOtqXNI1yvehPLdawAV9Vu57bs1U0366UNX8zWGxJGksdLKC7UIis/ed2r/ydcf4T31T+zjhl8F/VuPjFUhtxXChFQaX7FL9zvaXOq0JLZevo/fo7OuOTFQloozAS1m5ApZBKER2chfPbhauizLeotVDpbr045r3DZ1LPJHP8D/tabd1wPVLeN8NJn22y8Ax+UB2k2ho9VFy//cED7LQG+iwxukh0XghGH8F3e6WxVNSalxMWXFqxTK2er+9ynM5sbbRMh+U87OORNhsJZAJ6LMqCmZlIEu/004yUP3GjVzNS/sSNXmOVQFiz0LxeLlyCCPRP7+USKa87eneluY6CG7ztOP0MT6a/v/UfH+5wG80f4XSgPCa9pukZoJsbYXmXul57l7AY+kxf5moaR+TsJHir6V4iNn3njtk1zu4ELwv417/+B1BLBwiFl1pXhgYAACoLAABQSwECFQMUAAgACAB2eq9A2/ngh80AAAA9AQAALAAMAAAAAAAAAABApIEAAAAAcmVxXzdkNjQ3NmFjLWE3MjgtNDg2My04MDRlLWE1Nzg5ZDI5YzYzMC54bWxVWAgAVjyyT887sk9QSwECFQMUAAgACAC7eq9A5JyIO4YGAAAqCwAAMAAMAAAAAAAAAABApIE3AQAAcmVxXzdkNjQ3NmFjLWE3MjgtNDg2My04MDRlLWE1Nzg5ZDI5YzYzMC54bWwuc2lnVVgIAFI8sk9RPLJPUEsBAhUDFAAIAAgAwHavQL9M6ae4AgAADgYAAAsADAAAAAAAAAAAQKSBKwgAAHJlcXVlc3QueG1sVVgIAL47sk/HNbJPUEsBAhUDFAAIAAgAmnqvQIWXWleGBgAAKgsAAA8ADAAAAAAAAAAAQKSBLAsAAHJlcXVlc3QueG1sLnNpZ1VYCAAWPLJPFDyyT1BLBQYAAAAABAAEAF4BAAD/EQAAAAA=</smev:BinaryData></smev:AppDocument></smev:MessageData></typ:ChangeOrderStatusV243Request></soapenv:Body>";
            document.CertificateValue.Value = GetCertificate();

            //var objectToHash = SignedXmlDocument.Canonicalize(document.Body);
            var body     = Canonicalizer.GetObject(document.Document.GetXmlDocument(), "#body");
            var hashBody = HashData(body);

            document.DigestValue.Value = hashBody.Base64;


            //var signedInfo = SignedXmlDocument.Canonicalize(document.SignedInfo);
            //var signedInfo = Canonicalizer.GetObject2(document.Document.GetXmlDocument(), "#signedInfo");
            var signedInfo = Canonicalizer.GetObject(document.Document.GetXmlDocument(), "#SignedInfo");
            var signature  = SigningHash(HashData(signedInfo));

            document.SignedValue.Value = signature.Base64;

            Console.WriteLine(document);

            //if (!Verify(document.ToString().Replace("</soapenv:body>", " </soapenv:body>"), body, signedInfo)) throw new Exception("Not Correct Final Xml");
            //if (!Verify(document.ToString(), body, signedInfo)) throw new Exception("Not Correct Final Xml");



            //document.Signing( SignMessage( testBody ) );
            //document.Signing( SignMessage( document.Body.ToString() ) );
            //Console.WriteLine(testBody);
        }
        public static string GetDocument(SignedXmlDocument doc)
        {
            Transform transform = new XmlDsigExcC14NTransform();

            transform.LoadInput(doc.Document.GetXmlDocument());
            return(new StreamReader((MemoryStream)transform.GetOutput()).ReadToEnd());
        }
Exemple #3
0
        public bool Verify(string xml, string body, string signedInfo)
        {
            var document          = new SignedXmlDocument(xml).Document.GetXmlDocument();
            var correctBody       = Canonicalizer.GetObject(document, "#body") == body;
            var correctSignedInfo = Canonicalizer.GetObject(document, "#signedInfo") == signedInfo;

            return(correctBody && correctSignedInfo);
        }