public async Task <JsonResult> Verify(string text) { if (text == null) { return(new JsonResult(new InfoCert { Message = "Введите данные" })); } else { try { VerifyserviceClient wcfclient = new VerifyserviceClient(); string response = await wcfclient.VerifyXmlAsync(text); InfoCert verifyInfo = JsonConvert.DeserializeObject <InfoCert>(response); verifyInfo.Message = "Подпись успешно проверена"; return(new JsonResult(verifyInfo)); } catch (Exception e) { return(new JsonResult(new InfoCert { Message = "Произошла ошибка при обработке" })); } } }
public JsonResult Verify(string text) { if (text == null) { return(Json(new InfoCert { Message = "Введите данные" })); } else { try { XmlDocument xml = new XmlDocument(); xml.LoadXml(text); XmlElement xRoot = xml.DocumentElement; XmlNode data = xRoot.LastChild; var certdata = data.LastChild; var certxml = certdata.LastChild; var cert = certxml.LastChild; string certstr = cert.InnerText; certstr = certstr.Trim(); X509Certificate2 certinfo = new X509Certificate2(Convert.FromBase64String(certstr)); InfoCert response = new InfoCert() { Algorithm = certinfo.SignatureAlgorithm.FriendlyName, SerialNumber = certinfo.GetSerialNumberString(), NotAfter = certinfo.NotAfter.ToShortDateString(), SubjectName = certinfo.SubjectName.Name, IssuerName = certinfo.IssuerName.Name, Message = "Сертификат успешно распознан" }; return(Json(response)); } catch (Exception e) { return(Json(new InfoCert { Message = "Произошла ошибка при обработке" })); } } }