コード例 #1
0
        private string GetHash(SupportedHashAlgorithims hashType, string filePath)
        {
            switch (hashType)
            {
            case SupportedHashAlgorithims.MESSAGEDIGEST5:
                return(MakeHashString(MD5.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

            case SupportedHashAlgorithims.SECUREHASHALGORITHIM1:
                return(MakeHashString(SHA1.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

            case SupportedHashAlgorithims.SECUREHASHALGORITHIM256:
                return(MakeHashString(SHA256.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

            case SupportedHashAlgorithims.SECUREHASHALGORITHIM384:
                return(MakeHashString(SHA384.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

            case SupportedHashAlgorithims.SECUREHASHALGORITHIM512:
                return(MakeHashString(SHA512.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

                // TODO: Why do we need to do this?
#if !NETCOREAPP
            case SupportedHashAlgorithims.RACEINTEGRITYPRIMITIVESEVALUATIONMESSAGEDIGEST:
                return(MakeHashString(RIPEMD160.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));
#endif
            default:
                return("");
            }
        }
コード例 #2
0
 /// <summary>Gets the file hash.</summary>
 /// <param name="filePath">The file path.</param>
 /// <param name="hashType">Type of the hash.</param>
 /// <param name="target">The target.</param>
 public void GetFileHash(string filePath, SupportedHashAlgorithims hashType, KryptonLabel target) => target.Text = GetHash(hashType, filePath);