MD5哈希从字符串

编程入门 行业动态 更新时间:2024-10-27 20:35:08
本文介绍了MD5哈希从字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

需要得到的MD5哈希的字符串。 得到一个错误MD5为空。 我绑来从一个字符串32个字符的MD5哈希值。

使用(System.Security.Cryptography.MD5 MD5 =        System.Security.Cryptography.MD5.Create(TextToHash)) {     byte []的retVal的= md5.Hash;     StringBuilder的SB =新的StringBuilder();     的for(int i = 0; I< retVal.Length;我++)     {         sb.Append(retVal的[I]的ToString(X2));     } }

解决方案   

需要得到的MD5哈希的字符串。

那么首先您需要将字符串转换为二进制数据以某种形式。你怎么会取决于您的需求,但它很可能会 Encoding.GetBytes 对于一些编码......你需要解决的这编码虽然。这是否哈希需要匹配创建其他地方的哈希,例如?

  

得到一个错误MD5为空。

那是因为你使用的是 MD5.Create 不正确。该参数是一个的算法名称的。你几乎应该只使用参过载代替。

我怀疑你想要的东西,如:

字节[]哈希值; 使用MD5(MD5 = MD5.Create()) {     哈希= md5.ComputeHash(Encoding.UTF8.GetBytes(文本)); } //现在转换成二进制散列成文本,如果你一定要...

Need to get MD5 hash from string. Get an error MD5 is null. I am tying to get a 32 character MD5 hash from a string.

using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create("TextToHash")) { byte[] retVal = md5.Hash; StringBuilder sb = new StringBuilder(); for (int i = 0; i < retVal.Length; i++) { sb.Append(retVal[i].ToString("x2")); } }

解决方案

Need to get MD5 hash from string.

Then first you need to convert your string to binary data in some form. How you do that will depend on your requirements, but it'll probably be Encoding.GetBytes for some encoding... you need to work out which encoding though. Does this hash need to match the hash created somewhere else, for example?

Get an error MD5 is null.

That's because you're using MD5.Create incorrectly. The argument is an algorithm name. You should almost certainly just use the parameterless overload instead.

I suspect you want something like:

byte[] hash; using (MD5 md5 = MD5.Create()) { hash = md5.ComputeHash(Encoding.UTF8.GetBytes(text)); } // Now convert the binary hash into text if you must...

更多推荐

MD5哈希从字符串

本文发布于:2023-10-22 22:45:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518947.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!