예제 #1
0
 public string Sign(string thumbprint, string base64data)
 {
     CAdESCOM.CPStore store = new CAdESCOM.CPStore();
     store.Open();
     try
     {
         CAPICOM.Certificate cert   = GetCertByThumbprint(store, thumbprint);
         CAdESCOM.CPSigner   signer = new CAdESCOM.CPSigner();
         signer.Certificate = cert;
         signer.TSAAddress  = "http://cryptopro.ru/tsp/";
         CAdESCOM.CadesSignedData signedData = new CAdESCOM.CadesSignedData();
         signedData.ContentEncoding = CAdESCOM.CADESCOM_CONTENT_ENCODING_TYPE.CADESCOM_BASE64_TO_BINARY;
         signedData.Content         = base64data;
         try
         {
             return(signedData.SignCades(signer, CAdESCOM.CADESCOM_CADES_TYPE.CADESCOM_CADES_BES, true));
         }
         catch (Exception e)
         {
             throw new Exception("Sign error", e);
         }
     }
     finally
     {
         store.Close();
     }
 }
예제 #2
0
 private CAPICOM.Certificate GetCertByThumbprint(CAdESCOM.CPStore store, string thumbprint)
 {
     foreach (CAPICOM.Certificate cert in store.Certificates)
     {
         if (cert.Thumbprint.Equals(thumbprint) && cert.HasPrivateKey())
         {
             return(cert);
         }
     }
     throw new Exception("No certificate was found by thumbprint [" + thumbprint + "]");
 }
예제 #3
0
 public ExCert[] GetCertificates()
 {
     CAdESCOM.CPStore store = new CAdESCOM.CPStore();
     store.Open();
     try
     {
         CAPICOM.ICertificates icerts = store.Certificates;
         ExCert[] certs = new ExCert[icerts.Count];
         int      i     = 0;
         foreach (CAPICOM.Certificate cert in store.Certificates)
         {
             certs[i++] = new ExCert(cert);
         }
         return(certs);
     }
     finally
     {
         store.Close();
     }
 }
예제 #4
0
        /**/

        public string GetIDFileFromTicket(string ticketContent, Event e)
        {
            if (e.soapFileName.Contains("DP_OTORG1_") || e.soapFileName.Contains("DP_OTORG2_"))
            {
                return(GetIDFileFromTicket(ticketContent, "UTF-8"));
            }
            else
            {
                return(GetIDFileFromTicket(ticketContent, "windows-1251"));
            }
        }

        public string GetIDFileFromTicket(string ticketContent)
        {
            return(GetIDFileFromTicket(ticketContent, "windows-1251"));
        }

        public string GetIDFileFromTicket(string ticketContent, string encoding)
        {
            try
            {
                string      xmlString = Utils.Base64Decode(ticketContent, encoding);
                XmlDocument xml       = new XmlDocument();
                xml.LoadXml(xmlString);
                return(xml.SelectSingleNode("/Файл[@*]/@ИдФайл").InnerText + ".xml");
            }
            catch (Exception e)
            {
                Logger.error(e.StackTrace);
                throw e;
            }
        }

        private string authorize()
        {
            string            login    = conf.Login;
            string            password = conf.Api_pass;
            AuthorizeResponse response;

            try
            {
                response = (AuthorizeResponse)Http2.post <AuthorizeResponse>("https://api-service.edi.su/Api/Dixy/Index/Authorize", new AuthorizeRequest(login, password));
                return(response.varToken);
            }
            catch (Exception ex)
            {
                Logger.log("ERROR: api auth fails. Api funcs will NOT be able . Reason : " + ex.Message);
                return(null);
            }
        }

        /**/
        public ExCert GetExCertificate(string thumbprint)
        {
            CAdESCOM.CPStore store = new CAdESCOM.CPStore();
            store.Open();
            try
            {
                CAPICOM.ICertificates icerts = store.Certificates;
                ExCert[] certs = new ExCert[icerts.Count];
                int      i     = 0;
                foreach (CAPICOM.Certificate cert in store.Certificates)
                {
                    if (cert.Thumbprint.Equals(thumbprint) && cert.HasPrivateKey())
                    {
                        return(new ExCert(cert));
                    }
                }
                throw new Exception("No certificate was found by thumbprint [" + thumbprint + "]");
            }
            finally
            {
                store.Close();
            }
        }