黑莓连接code MD5在C#中从不同的MD5 [英] Blackberry encode MD5 different from MD5 in C#

查看:127
本文介绍了黑莓连接code MD5在C#中从不同的MD5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的密码连接在C#中的MD5 codeD和我的数据库插入。

I have my passwords encoded in MD5 in C# and inserted in my DB.

MD5 MD5Hasher = MD5.Create();
byte[] PasswordHash = MD5Hasher.ComputeHash(Encoding.Unicode.GetBytes(PasswordText.Value));

PasswordHash插入原样,看起来像 0x09C09E5B52580E477514FA .......... 例如

在黑莓应用程序,我得到了密码,要带code将其将其传递到Web服务,将比较这两个哈希密码。问题是我的结果是我在黑莓应用程序创建MD5不同。

In the blackberry app, I get the password, want to encode it to pass it to a web service that will compare both hashed password. The problem is my result is different from the MD5 I create in my Blackberry app.

password = Crypto.encodeStringMD5(password);

然后我下面的功能:

Then below my function:

    public static String encodeStringMD5(String s) throws Exception {
    byte[] bytes = s.getBytes();
    MD5Digest digest = new MD5Digest();
    digest.update(bytes, 0, bytes.length);
    int length = digest.getDigestLength();
    byte[] md5 = new byte[length];
    digest.getDigest(md5, 0, true);
    return convertToHex(md5);
}

private static String convertToHex(byte[] data) {
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < data.length; i++) {
        int halfbyte = (data[i] >>> 4) & 0x0F;
        int two_halfs = 0;
        do {
            if ((0 <= halfbyte) && (halfbyte <= 9))
                buf.append((char) ('0' + halfbyte));
            else
                buf.append((char) ('a' + (halfbyte - 10)));
            halfbyte = data[i] & 0x0F;
        } while(two_halfs++ < 1);
    }
    return buf.toString();
}

所以它返回这样的: 07054da3aea1cc98377fe0 ..........

任何想法,我怎么能得到我的黑莓我的C#函数来创建相同的哈希密码?

Any idea how I can get the same hashed password that I create with my C# function in the Blackberry?

感谢您!

推荐答案

的getBytes()的Java方法字符串返回.NET不同的编码比 Encoding.Uni code 。您需要指定明确的编码算法。使用UTF-8两个平台,你应该没问题。您也可以尝试在Java端GetBytes方法提供一个字符集名称;尝试的getBytes(UTF-16)

The getBytes() method of java String returns a different encoding than the Encoding.Unicode in .NET. You need to specify unambiguous encoding algorithms. Use UTF-8 for both platforms and you should be ok. You can also try providing a charset name to the getBytes method on the Java side; try getBytes("UTF-16")

这篇关于黑莓连接code MD5在C#中从不同的MD5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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