当前位置: 首页>>代码示例>>C#>>正文


C# this.ComputeHash方法代码示例

本文整理汇总了C#中this.ComputeHash方法的典型用法代码示例。如果您正苦于以下问题:C# this.ComputeHash方法的具体用法?C# this.ComputeHash怎么用?C# this.ComputeHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在this的用法示例。


在下文中一共展示了this.ComputeHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FromFile

 /// <summary>
 /// Get the MD5 hash value as a HEX-string
 /// </summary>
 /// <param name="md5">Instance of MD5</param>
 /// <param name="filepath">The input filepath for the hash code is to be calculated. </param>
 /// <returns>The calculated hash code as Hex-string</returns>
 public static string FromFile(this MD5 md5, string filepath)
 {
     using (var stream = File.OpenRead(filepath))
     {
         return md5.ComputeHash(stream).ToHexString();
     }
 }
开发者ID:rolbeh,项目名称:Magic.net,代码行数:13,代码来源:MagCryptographyExtension.cs

示例2: ComputeFileHash

 public static byte[] ComputeFileHash(this MD5CryptoServiceProvider md5, string filename)
 {
     using (var fileStream = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
     {
             return md5.ComputeHash(fileStream);
     }
 }
开发者ID:mcastagnasso,项目名称:rugicon,代码行数:7,代码来源:MD5CryptoServiceProviderExtensions.cs

示例3: ComputeHashString

 /// <summary>Computes the hash value for the specified <see cref="String" /> <paramref name="input"/>.</summary>
 /// <param name="md5">The <see cref="MD5" /> instance that will perform the hash computation.</param>
 /// <param name="input">A <see cref="String" /> value.</param>
 /// <param name="encoding">An <see cref="Encoding" /> object that will be used to encode <paramref name="input" /> to bytes.</param>
 /// <returns>A <see cref="String" /> containing the computed hash of <paramref name="input"/>.</returns>
 public static String ComputeHashString(this MD5 md5, String input, Encoding encoding)
 {            
     Byte[] inputBytes = encoding.GetBytes(input);
     var hashBuilder = new StringBuilder();
     List<Byte> hashBytes = md5.ComputeHash(inputBytes).ToList();
     hashBytes.ForEach(hashByte => hashBuilder.AppendFormat("{0:x2}", hashByte));
     return hashBuilder.ToString();            
 }
开发者ID:davelondon,项目名称:dontstayin,代码行数:13,代码来源:MD5Extensions.cs

示例4: ComputeHash

        public static string ComputeHash(this ICryptoService cryptoService, string data, string salt)
        {
            byte[] dataBytes = Encoding.UTF8.GetBytes(data);
            byte[] saltBytes = Convert.FromBase64String(salt);

            byte[] hashBytes = cryptoService.ComputeHash(dataBytes, saltBytes);

            return Convert.ToBase64String(hashBytes);
        }
开发者ID:bytefish,项目名称:NancyOwinExample,代码行数:9,代码来源:CryptoServiceExtensions.cs

示例5: ComputeHash

        public static string ComputeHash(this HashAlgorithm Hash, string Buffer)
        {
            StringBuilder digestString = new StringBuilder();

            foreach (byte b in Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Buffer)))
                digestString.Append(Convert.ToString(b, 16).PadLeft(2, '0'));

            return digestString.ToString();
        }
开发者ID:Prokochalov77,项目名称:php-vulnerability-hunter,代码行数:9,代码来源:HashAlgorithmExtension.cs

示例6: ComputeHashAsString

        public static string ComputeHashAsString(this HashAlgorithm hashAlgorithm, byte[] buffer)
        {
            var hashBytes = hashAlgorithm.ComputeHash(buffer);
            var builder = new StringBuilder();
            foreach (var @byte in hashBytes) {
                builder.Append(@byte.ToString("x"));
            }

            return builder.ToString();
        }
开发者ID:ashmind,项目名称:gallery,代码行数:10,代码来源:HashAlgorithmExtensions.cs

示例7: ComputeStringHash

 public static string ComputeStringHash(this HashAlgorithm algorithm, byte[] content)
 {
     var computedHash = algorithm.ComputeHash(content);
     var sb = new StringBuilder();
     for (var i = 0; i < computedHash.Length; i++)
     {
         sb.Append(computedHash[i].ToString("x2"));
     }
     return sb.ToString();
 }
开发者ID:steamcore,项目名称:CacheTag,代码行数:10,代码来源:HashAlgorithmExtensions.cs

示例8: ComputeHash

        /// <summary>
        /// Computes the hash value for the specified string.
        /// </summary>
        /// <param name="hashType">The type of algorithm to use when computing the hash.</param>
        /// <param name="value">The input to compute the hash code for.</param>
        /// <param name="encoding">
        /// The encoding to use when retrieving the binary representation of <paramref name="value"/>.
        /// If null or not supplied, then <see cref="Encoding.UTF8"/> is used instead.
        /// </param>
        /// <returns>The computed hash code.</returns>
        public static string ComputeHash(this HashType hashType, string value, Encoding encoding = null)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            encoding = encoding ?? Encoding.UTF8;

            return hashType.ComputeHash(encoding.GetBytes(value));
        }
开发者ID:RockFramework,项目名称:Rock.Core,代码行数:21,代码来源:HashTypeExtensions.cs

示例9: GetHash

        // MD5 Hash object to string conversion
        public static string GetHash(this MD5 str, string pass)
        {
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(pass);
            byte[] hash = str.ComputeHash(inputBytes);

            // Convert byte array to hex string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString();
        }
开发者ID:alex67x,项目名称:RomGeo,代码行数:14,代码来源:Extensions.cs

示例10: ComputeHash

        public static string ComputeHash(this SHA1 sha1, string input, Encoding encoding)
        {
            // step 1, calculate SHA1 hash from input
            var inputBytes = encoding.GetBytes(input);
            var hash = sha1.ComputeHash(inputBytes);

            // step 2, convert byte array to hex string
            var sb = new StringBuilder();
            foreach (var t in hash)
            {
                sb.Append(t.ToString("X2"));
            }
            return sb.ToString();
        }
开发者ID:Knight1988,项目名称:SharpUtility,代码行数:14,代码来源:SHA1Extensions.cs

示例11: GetHashedString

        public static string GetHashedString(this HashAlgorithm algorithm, string value)
        {
            if (string.IsNullOrEmpty(value)) return null;

            var hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(value));
            var sb = new StringBuilder();

            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("x2"));
            }

            return sb.ToString();
        }
开发者ID:zaLTys,项目名称:osfi,代码行数:14,代码来源:HashExtensions.cs

示例12: GetHash

        public static string GetHash(this HashAlgorithm alg, string text)
        {
            string result = null;

            // Convert plain text into a byte array.
            byte[] textBytes = Encoding.UTF8.GetBytes(text);

            byte[] hashBytes = alg.ComputeHash(textBytes);

            // Convert result into a base64-encoded string.
            result = Convert.ToBase64String(hashBytes);

            return result;
        }
开发者ID:lucaslra,项目名称:SPM,代码行数:14,代码来源:HashAlgorithmExtensions.cs

示例13: HashString

        public static string HashString(this System.Security.Cryptography.HashAlgorithm algo, string value, System.Text.Encoding encoding = null)
        {
            if (encoding == null) encoding = System.Text.Encoding.Default;

            algo.Initialize();
            byte[] hashBytes = algo.ComputeHash(encoding.GetBytes(value));

            StringBuilder sbHash = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sbHash.Append(hashBytes[i].ToString("x").ToLower().PadLeft(2, '0'));
            }
            return sbHash.ToString();
        }
开发者ID:alcexhim,项目名称:Indigo,代码行数:14,代码来源:HashAlgorithmExtensions.cs

示例14: ComputeIntHash

		public static unsafe int ComputeIntHash(this HashAlgorithm alg, byte[] dat)
		{
			int h;
			byte[] hash = alg.ComputeHash(dat);
			fixed(byte* barr = hash)
			{
				int* iarr = (int*)barr;
				h = iarr[0];
				for (int i = 1; i < hash.Length >> 2; i++)
				{
					h ^= iarr[i];
				}
			}
			return h;
		}
开发者ID:Orvid,项目名称:NeoAxis.ArchiveGenerator,代码行数:15,代码来源:HashAlgorithmExtensions.cs

示例15: ComputeHash

        public static byte[] ComputeHash(this HashAlgorithm hashAlgorithm, string fileName)
        {
            if (hashAlgorithm == null)
                throw new ArgumentNullException("hashAlgorithm");

            if (fileName == null)
                throw new ArgumentNullException("filename");

            if (!File.Exists(fileName))
                throw new FileNotFoundException("Unable to locate file", fileName);

            using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                return hashAlgorithm.ComputeHash(stream);
            }
        }
开发者ID:baughj,项目名称:Spark,代码行数:16,代码来源:HashAlgorithmExtender.cs


注:本文中的this.ComputeHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。