MD5哈希鉴于C#中的关键 [英] MD5 Hashing Given a Key in C#

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

问题描述

我一直在寻找一种方式来凑在C#中的字符串使用预定的密钥。

I've been looking for a way to hash a given string in C# that uses a predetermined key.

在通过互联网试图找到我已经看到很多MD5CryptoServiceProvider例子,这似乎要使用的机器默认密钥的例子我的故事,但他们都不适用特定键。我需要有一个特定的键对数据进行编码,以它同步到别人的服务器。我递给他们一个散列字符串和一个ID号,他们使用的分析数据并返回一组类似的给我。所以,反正是有得到的MD5通过特定的按键,这将是双方一致的哈希值。

On my adventures through the internet trying to find an example i have seen lots of MD5CryptoServiceProvider examples which seem to use a default key for the machine, but none of them that apply a specific key. I need to have a specific key to encode data as to synchronize it to someone else's server. I hand them a hashed string and an ID number and they use that analyze the data and return a similar set to me. So is there anyway to get md5 to hash via a specific key that would be consistent to both.

我宁愿这在C#来完成,但如果它不可能?与库可你有一些网络语言如PHP或ASP这么做

I would prefer this to be done in C#, but if its not possible with the libraries can you do so with some web languages like php or asp?

编辑:误解我被扔进和一个小会议后,思考为什么的情况,他们要我使用密钥似乎他们想要附加到字符串和散列的端部的键。这样,服务器可以追加关键它一起传递以确保其有效访问计算机中的数据。反正...感谢所有的^ _ ^

Misunderstood the scenario I was thrown into and after a little sitting and thinking about why they would have me use a key it appears they want a key appended to the end of the string and hashed. That way the server can appended the key it has along with the data passed to ensure its a valid accessing computer. Anyways... thanks all ^_^

EDIT2:如下我的评论说,这是术语盐析我是浑然不觉。哦越来越扔进新的东西,没有方向的乐趣。

As my comment below says, it was the term 'salting' I was oblivious to. Oh the joys of getting thrown into something new with no directions.

推荐答案

MD5不是加密 - 这是一个哈希值。它不允许一个字符串进行解密。

MD5 is not encryption - it's a hash. It doesn't allow a string to be decrypted.

您正在寻找一个对称加密算法。它采用相同的密钥来加密和解密。尝试使用加密功能,不理解他们是危险的。即使你认为你了解他们,你可以犯错误。

You're looking for a symmetric encryption algorithm. It uses the same key to encrypt and decrypt. Trying to use encryption functions without understanding them is dangerous. Even if you think you understand them, you can make a mistake.

如果你将数据传输到另一个人的服务器,你可以使用类似 GPG会更好到文件中使用对称密钥你们都同意通过电话的的或许有些公钥密码进行加密。这样一来,你不写任何加密代码,它的安全(不是完全安全的,请注意,但更安全)。

If you're transferring data to another person's server, you may be better off using something like gpg to encrypt the file using a symmetric key you both agree on over the phone, or perhaps some public-key crypto. This way, you don't write any crypto code, and it's safer (not completely secure, mind you, but safer).


编辑:我仍然试图破译你的要求。

I'm still trying to decipher your requirements.

MD5是一个unkeyed的哈希函数 - 有在使用中未键,所有的。所以我们可以说,服务器向您发送一个巨大的字符串,或者一个文件,它的哈希值。这样,你会MD5算法的字符串或文件,和比较你就打发哈希计算哈希值。如果它们匹配 - 数据为在途未损坏。这的的意思是没有人与他们送你在传输过程中被篡改,因为MD5没有秘诀吧。我可以MD5任何我想要的,并传送给你。

MD5 is an unkeyed hash function - there is not key in use at all. So let's say the server sends you a giant string, or a file, and a hash of it. You would then MD5 the string or file, and compare the hash you computed with the hash they sent. If they match - the data was not corrupted in transit. That doesn't mean no one tampered with what they sent you in transit, because MD5 has no "secret sauce" to it. I can md5 anything I want and send it to you.

一个HMAC是的加密散列函数的。它有一个秘方,只有你和你与之通信的组应该知道 - 密钥。如果他们给你一个长字符串或文件,和HMAC,你可以自己计算HMAC,比较你的HMAC和他们,如果他们匹配,数据中没有被损坏,也没有篡改数据

A HMAC is a keyed hash function. It has a secret ingredient that only you and the group you're communicating with should know - the secret key. If they send you a long string or file, and a HMAC, you can compute the HMAC yourself, compare your HMAC and theirs, and if they match, the data was not corrupted in transit, nor was the data tampered with.

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

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