匹配在C#中使用SQL创建一个散列 [英] Match a hash created in C# with sql

查看:119
本文介绍了匹配在C#中使用SQL创建一个散列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用来生成一个散列的方法:

I have a method used to generate a hash:

public static string GetMD5Hash(string input)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);

        bs = x.ComputeHash(bs);

        System.Text.StringBuilder s = new System.Text.StringBuilder();

        foreach (byte b in bs)
        {
            s.Append(b.ToString("x2").ToLower());
        }
        return s.ToString();
    }



我然后保存该散列一个varchar(255)列。知道什么原始的输入字符串是,那会是可能在存储在VARCHAR(255)列相同的散列值到达时,使用SQL(2005年)??

I then save that hash in a varchar(255) column. Knowing what the original input string was, would it be possible to to arrive at the same hash value stored in the varchar(255) column, using sql (2005)??

我已经试过像疯了似的用不同的数据类型,转换和HASHBYTES()函数,但一直没能得到接近。

I have tried like crazy using different data types, conversions and the hashbytes() function, but have not been able to get close.

我尝试失败的例子:(

select convert(varchar, hashbytes('MD5', convert(varbinary(200), '<censored>',0)))


推荐答案

这与#Cbleepbloop: 04d3f95947702213e23730a0e8fac6c3

from #c with "bleepbloop" : 04d3f95947702213e23730a0e8fac6c3

然后

select convert(varchar(32), hashbytes('MD5', 'bleepbloop'), 2)

>> 04D3F95947702213E23730A0E8FAC6C3

或者你可以存储和放大器,比较二进制。

Or You could just store & compare as binary.

这篇关于匹配在C#中使用SQL创建一个散列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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