哈希算法MD5 [英] Hashing algorithm md5

查看:84
本文介绍了哈希算法MD5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当向该方法提供文件路径时,谁能告诉我产生md5散列的最快方法.目前,我正在使用一种算法,该算法返回32个字节的哈希字符串.我的想法是,如果我可以得到这样的算法,该算法可以提供16个字节的哈希字符串,那么该过程可能会更快.我对此有些陌生,所以可能是错误的.请提供任何反馈.这就是我正在使用的代码.(在Code Project本身的一篇文章中对此进行了介绍.)

can any one tell me the fastest way to produce md5 hashes, when a filepath is provided to the method. At present I am using an algorithm which is returning hashed string of 32 bytes. What I think that, if I could get such an algorithm, which can provide hashed string of 16 bytes then the process could be much faster. I am a bit new to it, so may be wrong. Please provide any feedback. This is what I am using.(Got this in an article in Code Project itself).

System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher =
                     new System.Security.Cryptography.MD5CryptoServiceProvider();
           try
           {
               oFileStream = GetFileStream(pathName);
               arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);
               oFileStream.Close();
               strHashData = System.BitConverter.ToString(arrbytHashValue);
               strHashData = strHashData.Replace("-", "");
           }
           catch (System.Exception ex)
           {
           }




谢谢与问候
Anurag




Thanks and Regards
Anurag

推荐答案

你好Anurag,

MD5散列函数总是产生128位,占16个字节.十六进制的16个字节为32个字符.以十六进制表示时,字符串表示形式的MD5哈希不能少于32个字符.无论如何,这种情况下的计算时间很长,可能是由于文件大小所致.文件越大,计算哈希值所花费的时间就越长(您是否发现了computeHash正在馈入文件输入流的位置?).您的散列文件有多大,需要多长时间?

还有其他一些Hash函数可能更高效,但是是否可以使用它们取决于您的用例.

干杯

曼弗雷德(Manfred)
Hello Anurag,

a MD5 hash function always yields 128 bit which makes for 16 bytes. 16 bytes in hex are 32 characters. A MD5 hash in a string representation cannot be shorter than 32 characters when expressed in hex. Anyhow, the lengthy duration of the caculation in your case is probably due to the file size. The bigger the file the longer it takes to calculate the hash (Did you spot where computeHash is being fed the file input stream?). How big is that file your hashing and how long does it take?

There are other Hash functions that may be more performant but if you can use them or not depends on what your use case is.

Cheers

Manfred


这篇关于哈希算法MD5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆