Добрый день
Тестирую свой метод, который был создан на основе примера KK_XMLsign_example.
Обнаружилось очень странное поведение.
Код ниже успешно подписывает и проверяет xml, если брать его из переменной xmlToSignGood.
Но если попытаться подписать и проверить xml из переменной xmlToSignBad, то будет такая ошибка:
verifyXMLbytes START.
func=xmlSecOpenSSLEvpDigestVerify:file=digests.c:line=250:obj=gost34311:subj=unknown:error=12:invalid data:data and digest do not match
Signature is INVALID
verifyXMLbytes FINISH.
А ведь разница между ними только в наличии символов переноса строки внутри xml.
Можете помочь с этой проблемой?
public static string SignAndVerifyXmlString(string certFilePath, string certFilePassword, string rootCertPath)
{
XMLClass xmlEx = new XMLClass();
int res = xmlEx.initXML();
if (res != 0)
throw new Exception(String.Format("XMLClass initXML error"));
try
{
string xmlToSignGood = "<PaymentsListType2>\r\n<bankName>123</bankName></PaymentsListType2>";
string xmlToSignBad = "<PaymentsListType2><bankName>123</bankName></PaymentsListType2>";
string xmlToSign = xmlToSignGood;
//string xmlToSign = xmlToSignBad;
byte[] xmlBytesIn = Encoding.UTF8.GetBytes(xmlToSign);
byte[] xmlBytesOut = xmlEx.signXMLbytes(xmlBytesIn, certFilePath, certFilePassword);
if (xmlBytesOut.Length == 0)
throw new Exception(String.Format("Zero length result returned from the XMLClass signXMLbytes method"));
string[] sCertCA = new string[1];
sCertCA[0] = rootCertPath;
res = xmlEx.verifyXMLbytes(xmlBytesOut, sCertCA);
if (res != 1)
throw new Exception(String.Format("Error in verifyXMLbytes"));
string xmlSigned = Encoding.UTF8.GetString(xmlBytesOut);
return xmlSigned;
}
finally
{
//freeXML return int (0 - success; -1 - error)
res = xmlEx.freeXML();
}
}