Получение хэша от строки по гост 94: различия между версиями
Перейти к навигации
Перейти к поиску
Dmitriy (обсуждение | вклад) (Новая страница: «<pre> string signedInfo22 = "<SOAP-ENV:Body xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/…») |
Dmitriy (обсуждение | вклад) |
||
(не показаны 2 промежуточные версии этого же участника) | |||
Строка 1: | Строка 1: | ||
− | <pre> string signedInfo22 = "<SOAP-ENV:Body xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"BODY\"><PRPA_IN201301RU02 xmlns=\"urn:hl7-org:v3\" ITSVersion=\"XML_1.0\"><id extension=\"0\" root=\"1.2.643.5.1.13.3.25.35.11\"></id><creationTime value=\"20150209172931\"></creationTime><interactionId extension=\"PRPA_IN201301RU02\" root=\"1.2.643.5.1.13.2.7.3\"></interactionId><processingCode code=\"P\"></processingCode><processingModeCode code=\"T\"></processingModeCode><acceptAckCode code=\"AL\"></acceptAckCode><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"d5a0f9c0-5db4-11e3-949a-0800200c9a66\"></id><asAgent classCode=\"ASSIGNED\"><representedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.643.5.1.13.2.7.3\"></id><name>ИЭМК</name></representedOrganization></asAgent></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"d84c8524-d53e-43c6-973c-5076646731d8\"></id><name>МИС Вологодской области \"Статистика и счета ЛПУ\"</name><asAgent classCode=\"ASSIGNED\"><representedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.643.5.1.13.3.25.35.11\"></id><name>БУЗ ВО ВОЛОГОДСКАЯ ГОРОДСКАЯ ПОЛИКЛИНИКА 3</name></representedOrganization></asAgent></device></sender><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><subject typeCode=\"SUBJ\"><registrationEvent classCode=\"REG\" moodCode=\"EVN\"><id nullFlavor=\"NA\"></id><statusCode code=\"active\"></statusCode><subject1 typeCode=\"SBJ\"><patient classCode=\"PAT\"><id extension=\"3655\" root=\"1.2.643.5.1.13.3.25.35.11\"></id><statusCode code=\"active\"></statusCode><patientPerson><name><family> | + | <pre> string signedInfo22 = "<SOAP-ENV:Body xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"BODY\"><PRPA_IN201301RU02 xmlns=\"urn:hl7-org:v3\" ITSVersion=\"XML_1.0\"><id extension=\"0\" root=\"1.2.643.5.1.13.3.25.35.11\"></id><creationTime value=\"20150209172931\"></creationTime><interactionId extension=\"PRPA_IN201301RU02\" root=\"1.2.643.5.1.13.2.7.3\"></interactionId><processingCode code=\"P\"></processingCode><processingModeCode code=\"T\"></processingModeCode><acceptAckCode code=\"AL\"></acceptAckCode><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"d5a0f9c0-5db4-11e3-949a-0800200c9a66\"></id><asAgent classCode=\"ASSIGNED\"><representedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.643.5.1.13.2.7.3\"></id><name>ИЭМК</name></representedOrganization></asAgent></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"d84c8524-d53e-43c6-973c-5076646731d8\"></id><name>МИС Вологодской области \"Статистика и счета ЛПУ\"</name><asAgent classCode=\"ASSIGNED\"><representedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.643.5.1.13.3.25.35.11\"></id><name>БУЗ ВО ВОЛОГОДСКАЯ ГОРОДСКАЯ ПОЛИКЛИНИКА 3</name></representedOrganization></asAgent></device></sender><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><subject typeCode=\"SUBJ\"><registrationEvent classCode=\"REG\" moodCode=\"EVN\"><id nullFlavor=\"NA\"></id><statusCode code=\"active\"></statusCode><subject1 typeCode=\"SBJ\"><patient classCode=\"PAT\"><id extension=\"3655\" root=\"1.2.643.5.1.13.3.25.35.11\"></id><statusCode code=\"active\"></statusCode><patientPerson><name><family>XXXXXX</family><given>YYYYYYYY</given><given>ZZZZZZZZZZZZZZ</given></name><administrativeGenderCode code=\"2\" codeSystem=\"1.2.643.5.1.13.2.1.1.156\"></administrativeGenderCode><birthTime value=\"19590928\"></birthTime><addr><streetAddressLine>г. ВОЛОГДА, ул. FFFFFFFFFF кв.31</streetAddressLine><city>ВОЛОГДА</city><state>ВОЛОГОДСКАЯ</state><country>Российская Федерация</country></addr><asMember classCode=\"MBR\"><group classCode=\"PUB\"><code code=\"5\" codeSystem=\"1.2.643.5.1.13.2.1.1.366\" displayName=\"Неработающий\"></code></group></asMember><asMember classCode=\"MBR\"><group classCode=\"PUB\"><code code=\"2\" codeSystem=\"1.2.643.5.1.13.2.1.1.358\" displayName=\"инвалиды войны\"></code></group></asMember><asOtherIDs classCode=\"IDENT\"><documentType code=\"3\" codeSystem=\"1.2.643.5.1.13.2.7.1.62\"></documentType><documentNumber number=\"06377932094\"></documentNumber><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id nullFlavor=\"NI\"></id></scopingOrganization></asOtherIDs><asOtherIDs classCode=\"HLD\"><documentType code=\"1\" codeSystem=\"1.2.643.5.1.13.2.7.1.62\"></documentType><documentNumber number=\"3550040871001818\"></documentNumber><effectiveTime value=\"20120416\"></effectiveTime><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id extension=\"35003\" root=\"1.2.643.5.1.13.2.1.1.635\"></id><name>ОАО\"СТРАХОВАЯ КОМПАНИЯ \"СОГАЗ-МЕД\"</name></scopingOrganization></asOtherIDs><asOtherIDs classCode=\"IDENT\"><documentType code=\"5\" codeSystem=\"1.2.643.5.1.13.2.7.1.62\"><qualifier><name code=\"14\" codeSystem=\"1.2.643.5.1.13.2.1.1.498\" codeSystemName=\"Классификатор документов, удостоверяющих личность гражданина Российской Федерации\" displayName=\"Паспорт гражданина РФ\"></name></qualifier></documentType><documentNumber number=\"1909614992\"></documentNumber><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id nullFlavor=\"NI\"></id><name>УФМС Г.ВОЛОГДА</name></scopingOrganization></asOtherIDs><birthPlace><addr><city>Вологда</city><state>Российская Федерация</state></addr></birthPlace></patientPerson><providerOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.643.5.1.13.3.25.35.11\"></id><name>БУЗ ВО ВОЛОГОДСКАЯ ГОРОДСКАЯ ПОЛИКЛИНИКА 3</name><contactParty classCode=\"CON\"><telecom value=\"+8(8202)74-13-06\"></telecom></contactParty></providerOrganization></patient></subject1><custodian typeCode=\"CST\"><assignedEntity classCode=\"ASSIGNED\"><id root=\"1.2.643.5.1.13.3.25.35.11\"></id><assignedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><name>БУЗ ВО ВОЛОГОДСКАЯ ГОРОДСКАЯ ПОЛИКЛИНИКА 3</name></assignedOrganization></assignedEntity></custodian></registrationEvent></subject></controlActProcess></PRPA_IN201301RU02></SOAP-ENV:Body>"; |
HashAlgorithm myhash1 = HashAlgorithm.Create("Gost3411"); | HashAlgorithm myhash1 = HashAlgorithm.Create("Gost3411"); | ||
byte[] hashResult = myhash1.ComputeHash(Encoding.UTF8.GetBytes(signedInfo22)); | byte[] hashResult = myhash1.ComputeHash(Encoding.UTF8.GetBytes(signedInfo22)); | ||
− | |||
string canonicalHashedSignedInfo = Convert.ToBase64String(hashResult); | string canonicalHashedSignedInfo = Convert.ToBase64String(hashResult); | ||
Console.WriteLine(canonicalHashedSignedInfo); Console.ReadKey(); | Console.WriteLine(canonicalHashedSignedInfo); Console.ReadKey(); | ||
+ | </pre> | ||
+ | <pre> | ||
+ | static void hash_from_file_not_full(string _filenameXML, string _filenameTXT) | ||
+ | { | ||
+ | StreamWriter sw = new StreamWriter(_filenameTXT); | ||
+ | Gost3411 gost3411 = new Gost3411CryptoServiceProvider(); | ||
+ | const string Envelope = "/SOAP-ENV:Envelope"; | ||
+ | const string Header = Envelope + "/SOAP-ENV:Header"; | ||
+ | const string Action = Header + "/wsa:Action"; //wsa300 | ||
+ | const string MessageID = Header + "/wsa:MessageID"; //wsa301 | ||
+ | const string ReplyTo = Header + "/wsa:ReplyTo"; //wsa302 | ||
+ | const string To = Header + "/wsa:To"; //wsa303 | ||
+ | const string transportHeader = Header + "/egisz:transportHeader"; //TRHEAD | ||
+ | const string Security = Header + "/wsse:Security"; | ||
+ | const string ClinicalDocument = Envelope + "/SOAP-ENV:Body/ClinicalDocument"; | ||
+ | const string Body = Envelope + "/SOAP-ENV:Body"; | ||
+ | XmlDocument doc = new XmlDocument(); | ||
+ | doc.Load(new XmlTextReader(_filenameXML)); | ||
+ | var ns = new XmlNamespaceManager(doc.NameTable); | ||
+ | ns.AddNamespace("SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope"); | ||
+ | ns.AddNamespace("wsa", "http://www.w3.org/2005/08/addressing"); | ||
+ | ns.AddNamespace("egisz", "http://egisz.rosminzdrav.ru"); | ||
+ | XmlElement root = doc.DocumentElement; // Полный xml файл | ||
+ | // Console.WriteLine(root.InnerXml); Console.ReadKey(); | ||
+ | // Ищем тег Body, с нэмспейсом | ||
+ | XmlNode BodyInfo = doc.SelectSingleNode(Body, ns); | ||
+ | String BodyFile = BodyInfo.OuterXml; // Получаем полное содержимое тега Body | ||
+ | sw.Write("BodyFromFile= "); sw.WriteLine(BodyFile); // Пишем исходное body в файл | ||
+ | byte[] result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(BodyFile)); | ||
+ | sw.Write("HashBodyFile= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного body | ||
+ | // Приводим тэг Body к канонической форме | ||
+ | String BodyCan2 = Canonicalization(BodyInfo); | ||
+ | sw.Write("CanonicalBody= "); sw.WriteLine(BodyCan2); | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(BodyCan2)); | ||
+ | sw.Write("HashCanonicalBody= "); sw.WriteLine(Convert.ToBase64String(result)); | ||
+ | export_can_node(BodyCan2, "doc/Body_cann"); // экспорт результата каноникализации в файл | ||
+ | sw.WriteLine("********************************"); | ||
+ | // Ищем тег Action, с нэмспейсом | ||
+ | XmlNode Wsa300Info = doc.SelectSingleNode(Action, ns); | ||
+ | String WSA300File = Wsa300Info.OuterXml; // Получаем полное содержимое тега | ||
+ | sw.Write("WSA300FromFile= "); sw.WriteLine(WSA300File); // Пишем исходное в файл | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSA300File)); | ||
+ | sw.Write("HashWSA300File= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного body | ||
+ | // Приводим тэг к канонической форме | ||
+ | String WSACan2 = Canonicalization(Wsa300Info); | ||
+ | sw.Write("CanonicalWSA300= "); sw.WriteLine(WSACan2); | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSACan2)); | ||
+ | sw.Write("HashCanonicalWSA300= "); sw.WriteLine(Convert.ToBase64String(result)); | ||
+ | export_can_node(WSACan2, "doc/WSA300_cann"); // экспорт результата каноникализации в файл | ||
+ | sw.WriteLine("********************************"); | ||
+ | XmlNode WSA301Info = doc.SelectSingleNode(MessageID, ns); | ||
+ | sw.Write("WSA301FromFile= "); sw.WriteLine(WSA301Info.OuterXml); // Пишем исходное в файл | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSA301Info.OuterXml)); | ||
+ | sw.Write("HashWSA301File= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного | ||
+ | // Приводим тэг к канонической форме | ||
+ | sw.Write("CanonicalWSA301= "); sw.WriteLine(Canonicalization(WSA301Info)); | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(Canonicalization(WSA301Info))); | ||
+ | sw.Write("HashWSA301Cann= "); sw.WriteLine(Convert.ToBase64String(result)); | ||
+ | export_can_node(Canonicalization(WSA301Info), "doc/WSA301_cann"); // экспорт результата каноникализации в файл | ||
+ | sw.WriteLine("********************************"); | ||
+ | XmlNode WSA302Info = doc.SelectSingleNode(ReplyTo, ns); | ||
+ | sw.Write("WSA302FromFile= "); sw.WriteLine(WSA302Info.OuterXml); // Пишем исходное в файл | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSA302Info.OuterXml)); | ||
+ | sw.Write("HashWSA302File= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного | ||
+ | // Приводим тэг к канонической форме | ||
+ | sw.Write("CanonicalWSA302= "); sw.WriteLine(Canonicalization(WSA302Info)); | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(Canonicalization(WSA302Info))); | ||
+ | sw.Write("HashWSA302Cann= "); sw.WriteLine(Convert.ToBase64String(result)); | ||
+ | export_can_node(Canonicalization(WSA302Info), "doc/WSA302_cann"); // экспорт результата каноникализации в файл | ||
+ | sw.WriteLine("********************************"); | ||
+ | XmlNode WSA303Info = doc.SelectSingleNode(To, ns); | ||
+ | sw.Write("WSA303FromFile= "); sw.WriteLine(WSA303Info.OuterXml); // Пишем исходное в файл | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSA303Info.OuterXml)); | ||
+ | sw.Write("HashWSA303File= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного | ||
+ | // Приводим тэг к канонической форме | ||
+ | sw.Write("CanonicalWSA303= "); sw.WriteLine(Canonicalization(WSA303Info)); | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(Canonicalization(WSA303Info))); | ||
+ | sw.Write("HashWSA303Cann= "); sw.WriteLine(Convert.ToBase64String(result)); | ||
+ | export_can_node(Canonicalization(WSA303Info), "doc/WSA303_cann"); // экспорт результата каноникализации в файл | ||
+ | sw.WriteLine("********************************"); | ||
+ | XmlNode TRHEADInfo = doc.SelectSingleNode(transportHeader, ns); | ||
+ | sw.Write("TRHEADFromFile= "); sw.WriteLine(TRHEADInfo.OuterXml); // Пишем исходное в файл | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(TRHEADInfo.OuterXml)); | ||
+ | sw.Write("HashTRHEADFile= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного | ||
+ | // Приводим тэг к канонической форме | ||
+ | sw.Write("CanonicalTRHEAD= "); sw.WriteLine(Canonicalization(TRHEADInfo)); | ||
+ | result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(Canonicalization(TRHEADInfo))); | ||
+ | sw.Write("HashTRHEADCann= "); sw.WriteLine(Convert.ToBase64String(result)); | ||
+ | export_can_node(Canonicalization(TRHEADInfo), "doc/WSATRHEAD_cann"); // экспорт результата каноникализации в файл | ||
+ | sw.WriteLine("********************************"); | ||
+ | |||
+ | // Console.WriteLine(signedInfo.InnerXml); Console.ReadKey(); | ||
+ | sw.Close(); | ||
+ | return; | ||
</pre> | </pre> |
Текущая версия на 10:07, 6 мая 2015
string signedInfo22 = "<SOAP-ENV:Body xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"BODY\"><PRPA_IN201301RU02 xmlns=\"urn:hl7-org:v3\" ITSVersion=\"XML_1.0\"><id extension=\"0\" root=\"1.2.643.5.1.13.3.25.35.11\"></id><creationTime value=\"20150209172931\"></creationTime><interactionId extension=\"PRPA_IN201301RU02\" root=\"1.2.643.5.1.13.2.7.3\"></interactionId><processingCode code=\"P\"></processingCode><processingModeCode code=\"T\"></processingModeCode><acceptAckCode code=\"AL\"></acceptAckCode><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"d5a0f9c0-5db4-11e3-949a-0800200c9a66\"></id><asAgent classCode=\"ASSIGNED\"><representedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.643.5.1.13.2.7.3\"></id><name>ИЭМК</name></representedOrganization></asAgent></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id root=\"d84c8524-d53e-43c6-973c-5076646731d8\"></id><name>МИС Вологодской области \"Статистика и счета ЛПУ\"</name><asAgent classCode=\"ASSIGNED\"><representedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.643.5.1.13.3.25.35.11\"></id><name>БУЗ ВО ВОЛОГОДСКАЯ ГОРОДСКАЯ ПОЛИКЛИНИКА 3</name></representedOrganization></asAgent></device></sender><controlActProcess classCode=\"CACT\" moodCode=\"EVN\"><subject typeCode=\"SUBJ\"><registrationEvent classCode=\"REG\" moodCode=\"EVN\"><id nullFlavor=\"NA\"></id><statusCode code=\"active\"></statusCode><subject1 typeCode=\"SBJ\"><patient classCode=\"PAT\"><id extension=\"3655\" root=\"1.2.643.5.1.13.3.25.35.11\"></id><statusCode code=\"active\"></statusCode><patientPerson><name><family>XXXXXX</family><given>YYYYYYYY</given><given>ZZZZZZZZZZZZZZ</given></name><administrativeGenderCode code=\"2\" codeSystem=\"1.2.643.5.1.13.2.1.1.156\"></administrativeGenderCode><birthTime value=\"19590928\"></birthTime><addr><streetAddressLine>г. ВОЛОГДА, ул. FFFFFFFFFF кв.31</streetAddressLine><city>ВОЛОГДА</city><state>ВОЛОГОДСКАЯ</state><country>Российская Федерация</country></addr><asMember classCode=\"MBR\"><group classCode=\"PUB\"><code code=\"5\" codeSystem=\"1.2.643.5.1.13.2.1.1.366\" displayName=\"Неработающий\"></code></group></asMember><asMember classCode=\"MBR\"><group classCode=\"PUB\"><code code=\"2\" codeSystem=\"1.2.643.5.1.13.2.1.1.358\" displayName=\"инвалиды войны\"></code></group></asMember><asOtherIDs classCode=\"IDENT\"><documentType code=\"3\" codeSystem=\"1.2.643.5.1.13.2.7.1.62\"></documentType><documentNumber number=\"06377932094\"></documentNumber><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id nullFlavor=\"NI\"></id></scopingOrganization></asOtherIDs><asOtherIDs classCode=\"HLD\"><documentType code=\"1\" codeSystem=\"1.2.643.5.1.13.2.7.1.62\"></documentType><documentNumber number=\"3550040871001818\"></documentNumber><effectiveTime value=\"20120416\"></effectiveTime><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id extension=\"35003\" root=\"1.2.643.5.1.13.2.1.1.635\"></id><name>ОАО\"СТРАХОВАЯ КОМПАНИЯ \"СОГАЗ-МЕД\"</name></scopingOrganization></asOtherIDs><asOtherIDs classCode=\"IDENT\"><documentType code=\"5\" codeSystem=\"1.2.643.5.1.13.2.7.1.62\"><qualifier><name code=\"14\" codeSystem=\"1.2.643.5.1.13.2.1.1.498\" codeSystemName=\"Классификатор документов, удостоверяющих личность гражданина Российской Федерации\" displayName=\"Паспорт гражданина РФ\"></name></qualifier></documentType><documentNumber number=\"1909614992\"></documentNumber><scopingOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id nullFlavor=\"NI\"></id><name>УФМС Г.ВОЛОГДА</name></scopingOrganization></asOtherIDs><birthPlace><addr><city>Вологда</city><state>Российская Федерация</state></addr></birthPlace></patientPerson><providerOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.643.5.1.13.3.25.35.11\"></id><name>БУЗ ВО ВОЛОГОДСКАЯ ГОРОДСКАЯ ПОЛИКЛИНИКА 3</name><contactParty classCode=\"CON\"><telecom value=\"+8(8202)74-13-06\"></telecom></contactParty></providerOrganization></patient></subject1><custodian typeCode=\"CST\"><assignedEntity classCode=\"ASSIGNED\"><id root=\"1.2.643.5.1.13.3.25.35.11\"></id><assignedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><name>БУЗ ВО ВОЛОГОДСКАЯ ГОРОДСКАЯ ПОЛИКЛИНИКА 3</name></assignedOrganization></assignedEntity></custodian></registrationEvent></subject></controlActProcess></PRPA_IN201301RU02></SOAP-ENV:Body>"; HashAlgorithm myhash1 = HashAlgorithm.Create("Gost3411"); byte[] hashResult = myhash1.ComputeHash(Encoding.UTF8.GetBytes(signedInfo22)); string canonicalHashedSignedInfo = Convert.ToBase64String(hashResult); Console.WriteLine(canonicalHashedSignedInfo); Console.ReadKey();
static void hash_from_file_not_full(string _filenameXML, string _filenameTXT) { StreamWriter sw = new StreamWriter(_filenameTXT); Gost3411 gost3411 = new Gost3411CryptoServiceProvider(); const string Envelope = "/SOAP-ENV:Envelope"; const string Header = Envelope + "/SOAP-ENV:Header"; const string Action = Header + "/wsa:Action"; //wsa300 const string MessageID = Header + "/wsa:MessageID"; //wsa301 const string ReplyTo = Header + "/wsa:ReplyTo"; //wsa302 const string To = Header + "/wsa:To"; //wsa303 const string transportHeader = Header + "/egisz:transportHeader"; //TRHEAD const string Security = Header + "/wsse:Security"; const string ClinicalDocument = Envelope + "/SOAP-ENV:Body/ClinicalDocument"; const string Body = Envelope + "/SOAP-ENV:Body"; XmlDocument doc = new XmlDocument(); doc.Load(new XmlTextReader(_filenameXML)); var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope"); ns.AddNamespace("wsa", "http://www.w3.org/2005/08/addressing"); ns.AddNamespace("egisz", "http://egisz.rosminzdrav.ru"); XmlElement root = doc.DocumentElement; // Полный xml файл // Console.WriteLine(root.InnerXml); Console.ReadKey(); // Ищем тег Body, с нэмспейсом XmlNode BodyInfo = doc.SelectSingleNode(Body, ns); String BodyFile = BodyInfo.OuterXml; // Получаем полное содержимое тега Body sw.Write("BodyFromFile= "); sw.WriteLine(BodyFile); // Пишем исходное body в файл byte[] result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(BodyFile)); sw.Write("HashBodyFile= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного body // Приводим тэг Body к канонической форме String BodyCan2 = Canonicalization(BodyInfo); sw.Write("CanonicalBody= "); sw.WriteLine(BodyCan2); result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(BodyCan2)); sw.Write("HashCanonicalBody= "); sw.WriteLine(Convert.ToBase64String(result)); export_can_node(BodyCan2, "doc/Body_cann"); // экспорт результата каноникализации в файл sw.WriteLine("********************************"); // Ищем тег Action, с нэмспейсом XmlNode Wsa300Info = doc.SelectSingleNode(Action, ns); String WSA300File = Wsa300Info.OuterXml; // Получаем полное содержимое тега sw.Write("WSA300FromFile= "); sw.WriteLine(WSA300File); // Пишем исходное в файл result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSA300File)); sw.Write("HashWSA300File= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного body // Приводим тэг к канонической форме String WSACan2 = Canonicalization(Wsa300Info); sw.Write("CanonicalWSA300= "); sw.WriteLine(WSACan2); result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSACan2)); sw.Write("HashCanonicalWSA300= "); sw.WriteLine(Convert.ToBase64String(result)); export_can_node(WSACan2, "doc/WSA300_cann"); // экспорт результата каноникализации в файл sw.WriteLine("********************************"); XmlNode WSA301Info = doc.SelectSingleNode(MessageID, ns); sw.Write("WSA301FromFile= "); sw.WriteLine(WSA301Info.OuterXml); // Пишем исходное в файл result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSA301Info.OuterXml)); sw.Write("HashWSA301File= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного // Приводим тэг к канонической форме sw.Write("CanonicalWSA301= "); sw.WriteLine(Canonicalization(WSA301Info)); result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(Canonicalization(WSA301Info))); sw.Write("HashWSA301Cann= "); sw.WriteLine(Convert.ToBase64String(result)); export_can_node(Canonicalization(WSA301Info), "doc/WSA301_cann"); // экспорт результата каноникализации в файл sw.WriteLine("********************************"); XmlNode WSA302Info = doc.SelectSingleNode(ReplyTo, ns); sw.Write("WSA302FromFile= "); sw.WriteLine(WSA302Info.OuterXml); // Пишем исходное в файл result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSA302Info.OuterXml)); sw.Write("HashWSA302File= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного // Приводим тэг к канонической форме sw.Write("CanonicalWSA302= "); sw.WriteLine(Canonicalization(WSA302Info)); result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(Canonicalization(WSA302Info))); sw.Write("HashWSA302Cann= "); sw.WriteLine(Convert.ToBase64String(result)); export_can_node(Canonicalization(WSA302Info), "doc/WSA302_cann"); // экспорт результата каноникализации в файл sw.WriteLine("********************************"); XmlNode WSA303Info = doc.SelectSingleNode(To, ns); sw.Write("WSA303FromFile= "); sw.WriteLine(WSA303Info.OuterXml); // Пишем исходное в файл result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(WSA303Info.OuterXml)); sw.Write("HashWSA303File= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного // Приводим тэг к канонической форме sw.Write("CanonicalWSA303= "); sw.WriteLine(Canonicalization(WSA303Info)); result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(Canonicalization(WSA303Info))); sw.Write("HashWSA303Cann= "); sw.WriteLine(Convert.ToBase64String(result)); export_can_node(Canonicalization(WSA303Info), "doc/WSA303_cann"); // экспорт результата каноникализации в файл sw.WriteLine("********************************"); XmlNode TRHEADInfo = doc.SelectSingleNode(transportHeader, ns); sw.Write("TRHEADFromFile= "); sw.WriteLine(TRHEADInfo.OuterXml); // Пишем исходное в файл result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(TRHEADInfo.OuterXml)); sw.Write("HashTRHEADFile= "); sw.WriteLine(Convert.ToBase64String(result)); // Пишем хэш исходного // Приводим тэг к канонической форме sw.Write("CanonicalTRHEAD= "); sw.WriteLine(Canonicalization(TRHEADInfo)); result = gost3411.ComputeHash(Encoding.UTF8.GetBytes(Canonicalization(TRHEADInfo))); sw.Write("HashTRHEADCann= "); sw.WriteLine(Convert.ToBase64String(result)); export_can_node(Canonicalization(TRHEADInfo), "doc/WSATRHEAD_cann"); // экспорт результата каноникализации в файл sw.WriteLine("********************************"); // Console.WriteLine(signedInfo.InnerXml); Console.ReadKey(); sw.Close(); return;