private bool VerifySignature(byte[] messageBytes, byte[] encodeMessage)
 {
     try
     {
         ContentInfo cont     = new ContentInfo(messageBytes);
         SignedCms   verified = new SignedCms(cont, true);
         verified.Decode(encodeMessage);
         X509Certificate2Collection Collection =
             new X509Certificate2Collection(_RecipientCert);
         try
         {
             verified.CheckSignature(Collection, true);
             if (verified.Certificates.Count > 0)
             {
                 if (!verified.Certificates[0].Equals(_RecipientCert))
                 {
                     return(false);
                 }
             }
         }
         catch (Exception exx)
         {
             NLogLogger.Info("" + exx);
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         NLogLogger.Info("" + ex);
         throw ex;
     }
 }
 /// <summary>
 /// Verifies the digital signatures on the signed CMS/PKCS #7 message.
 /// </summary>
 public bool Verify(string TextData, string DigitalSignature)
 {
     byte[] encodeMessage = null;
     try
     {
         encodeMessage = Convert.FromBase64String(DigitalSignature);
     }
     catch (Exception ex)
     {
         NLogLogger.Info("" + ex);
         return(false);
     }
     return(VerifySignature(_Enc.GetBytes(TextData), encodeMessage));
 }
Exemple #3
0
        public static void Download(string filepath, string filename)
        {
            Stream iStream = null;
            var    buffer  = new Byte[100000];

            try
            {
                iStream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
                var dataToRead = iStream.Length;
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
                while (dataToRead > 0)
                {
                    if (HttpContext.Current.Response.IsClientConnected)
                    {
                        var length = iStream.Read(buffer, 0, 100000);
                        HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
                        HttpContext.Current.Response.Flush();
                        buffer     = new Byte[100000];
                        dataToRead = dataToRead - length;
                    }
                    else
                    {
                        dataToRead = -1;
                    }
                }
            }
            catch (Exception ex)
            {
                File.Delete(filepath);
                NLogLogger.Info(ex.ToString());
                HttpContext.Current.Response.Write("Error :  " + ex.Message);
                Back();
            }
            finally
            {
                if (iStream != null)
                {
                    iStream.Close();
                }
                HttpContext.Current.Response.Close();
                File.Delete(filepath);
            }
        }