Коллеги,
Бороздя просторы обнаружил полезный метод как подписывать без помощи сторонних либ - средствами .NET. Попробовал этот метод с сертификатом RSA, с ГОСТ не заработало - из файла грузить не захотело, а проимпортировать его не получилось так как винда не видит поставщика ГОСТ (кстати его можно как то поставить?)
В нашем случае код выглядит следующим образом:
private static XmlDocument SignXmlDocument(Stream xmlStream, string guid)
{
X509Store store = new X509Store("My", StoreLocation.CurrentUser);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
// NUC RK (RSA) certificate imported to my PC - Личный сертификаты
X509Certificate2 foundCertificate = store.Certificates[0];
// load xml from disk preserving whitespaces
XmlDocument xmlDocument = new XmlDocument { PreserveWhitespace = true };
xmlDocument.Load(xmlStream);
// create signed xml with a same-document reference containing an enveloped-signature transform
SignedXml signedXml = new SignedXml(xmlDocument) { SigningKey = foundCertificate.PrivateKey };
Reference reference = new Reference();
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
XmlDsigC14NWithCommentsTransform c14 = new XmlDsigC14NWithCommentsTransform();
reference.AddTransform(env);
reference.AddTransform(c14);
reference.Uri = "#"+guid;
signedXml.AddReference(reference);
// embed public key information for signature validation purposes
KeyInfo keyInfo = new KeyInfo();
KeyInfoX509Data keyInfoX509Data = new KeyInfoX509Data(foundCertificate, X509IncludeOption.ExcludeRoot);
keyInfo.AddClause(keyInfoX509Data);
signedXml.KeyInfo = keyInfo;
// compute and retreive the signature xml
signedXml.ComputeSignature();
XmlElement xmldsigXmlElement = signedXml.GetXml();
// insert the signature xml into the xml document as first child of the root element
xmlDocument.GetElementsByTagName("soap:Header").Item(0).PrependChild(xmlDocument.ImportNode(xmldsigXmlElement, true));
return xmlDocument;
}
Жду ответа от ГЦВП по поводу своей 502 ошибки....Баха, может всё таки поделишься кодом с которым ты дошел до Invalid Signature? Я уже не знаю что дальше пробовать...