Beispiel #1
0
        //// NOTE: Leave out the finalizer altogether if this class doesn't
        //// own unmanaged resources itself, but leave the other methods
        //// exactly as they are.
        //~Encryption()
        //{
        //    // Finalizer calls Dispose(false)
        //    Dispose(false);
        //}

        // The bulk of the clean-up code is implemented in Dispose(bool)
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Free managed resources.
                lock (MacProviderLock)
                {
                    if (_MacProvider != null)
                    {
                        _MacProvider.Dispose();
                        _MacProvider = null;
                    }
                }
                lock (RsaProviderLock)
                {
                    if (_RsaProvider != null)
                    {
                        _RsaProvider.Dispose();
                        _RsaProvider = null;
                    }
                }
                if (_RsaSignatureHashAlgorithm != null)
                {
                    _RsaSignatureHashAlgorithm.Dispose();
                    _RsaSignatureHashAlgorithm = null;
                }
            }
        }
Beispiel #2
0
        public byte[] GetAssemblyHash()
        {
            System.Security.Cryptography.HashAlgorithm HA = System.Security.Cryptography.SHA256.Create();

            try
            {
                byte[] b;
                using (System.IO.FileStream fs = new System.IO.FileStream(GetAssemblyPath(), System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    b = HA.ComputeHash(fs);
                return(b);
            }
            catch
            {
                return(null);
                //Random r = new Random();
                //int keyLen = 128;
                //byte[] b = new byte[keyLen];
                //r.NextBytes(b);
                //return b;
            }
            finally
            {
                HA.Dispose();
            }
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _hashAlgorithm.Dispose();
     }
     base.Dispose(disposing);
 }
Beispiel #4
0
        private string MD5HashCode(HttpPostedFileBase file)
        {
            if (file.InputStream.CanSeek)
            {
                file.InputStream.Seek(0, SeekOrigin.Begin);
            }

            System.Security.Cryptography.HashAlgorithm hashAlgorithm = System.Security.Cryptography.MD5.Create();

            byte[] hashCode = hashAlgorithm.ComputeHash(file.InputStream);

            hashAlgorithm.Dispose();

            return(BitConverter.ToString(hashCode).Replace("-", ""));
        }
Beispiel #5
0
 public virtual void Dispose(bool _disposing)
 {
     _hashAlgorithm.Dispose();
 }