由于项目是借用别人提供的接口,其中有一段NET MD5 加密方法,代码如下
public string Encrypt(string as_fpassword)
{
///获取Byte数组
Byte[] clearBytes = new UnicodeEncoding().GetBytes(as_fpassword);
///获取Hash值
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes); ///获取加密后的信息
return BitConverter.ToString(hashedBytes).Replace("-",""); }现在想将上面代码翻译成 JAVA 版本的MD5加密。因为本人通过Java写的MD5与上面NET MD5加密的方法
得到结果始终不同。
求知道帮帮啦。谢谢各位。
public string Encrypt(string as_fpassword)
{
///获取Byte数组
Byte[] clearBytes = new UnicodeEncoding().GetBytes(as_fpassword);
///获取Hash值
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes); ///获取加密后的信息
return BitConverter.ToString(hashedBytes).Replace("-",""); }现在想将上面代码翻译成 JAVA 版本的MD5加密。因为本人通过Java写的MD5与上面NET MD5加密的方法
得到结果始终不同。
求知道帮帮啦。谢谢各位。
net 版结果为 5FA285E1BEBE0A6623E33AFC04A1FBD5
java 版结果为 202CB962AC59075B964B07152D234B70
public byte[] ComputeHash(byte[] buffer)
{
if (this.m_bDisposed)
{
throw new ObjectDisposedException(null);
}
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
this.HashCore(buffer, 0, buffer.Length);
this.HashValue = this.HashFinal();
byte[] buffer2 = (byte[]) this.HashValue.Clone();
this.Initialize();
return buffer2;
}
java 结果 900150983cd24fb0d6963f7d28e17f72