如何获取单向散列在.NET中给定的字符串? [英] How to obtain one-way hash for given string in .NET?

查看:127
本文介绍了如何获取单向散列在.NET中给定的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个内置的库在.NET中,可以计算安全的单向散列?我的意思是一个库,实现 SHA-2加密散列函数或类似的东西。

Is there a build in library in .NET that can compute secure one-way hash ? I mean a library that implements SHA-2 cryptographic hash function or something similar.

如果是不存在的SHA-2实现一些实力较弱的哈希funcion就足够了。 如果有更多的选择,我preFER最安全的。

If is there is no SHA-2 implementation some weaker hash funcion would be sufficient. If there are more options I prefer the most secure one.

请提供一个使用例如提供code,返回单向散列字符串 mySampleString

Please provide a use example e.g. provide the code that returns one-way hash for string mySampleString.

编辑:请提供例子,使用的哈希算法

Please provide the example and the hash algorithm used.

推荐答案

您可以使用的 SHA256Mananged 类来生成一个字符串的哈希值。该 ComputeHash 文档提供了一个完整的例子。

You can use the SHA256Mananged class to generate a hash of a string. The ComputeHash documentation provides a complete example.

如果您是针对Vista的+只是,你可以使用更快的 SHA256Cng 类代替。只要知道它会抛出XP。

If you are targeting Vista+ only, you can use the faster SHA256Cng class instead. Just realize that it will throw on XP.

这篇关于如何获取单向散列在.NET中给定的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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