import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;public class KeyedDigestMD5 {
    
public static byte[] getKeyedDigest(byte[] buffer, byte[] key) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(buffer);
            return md5.digest(key);
        } catch (NoSuchAlgorithmException e) {
        }
        return null;
    }


public static String getKeyedDigest(String strSrc, String key) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(strSrc.getBytes("UTF8"));
            
            String result="";
            byte[] temp;
            temp=md5.digest(key.getBytes("UTF8"));
     for (int i=0; i<temp.length; i++){
     result+=Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6);
     }
    
     return result;
    
        } catch (NoSuchAlgorithmException e) {
        
         e.printStackTrace();
        
        }catch(Exception e)
        {
          e.printStackTrace();
        }
        return null;
    }
public static void main(String[] args) {
// TODO Auto-generated method stub
String mi;
        String s = "hf1000";
 
mi=KeyedDigestMD5.getKeyedDigest(s,"");

System.out.println("mi:"+mi);


}}

解决方案 »

  1.   

    百度或google “c# md5加密”
      

  2.   

     我是写把jsp这个语法转成asp.net的语法啦
      

  3.   

    你有这个时间还不如找个c#的md5加密
      

  4.   

    http://tangiblesoftwaresolutions.com/
    试试
      

  5.   

    主要是这段看不懂
    MessageDigest md5 = MessageDigest.getInstance("MD5");
      md5.update(strSrc.getBytes("UTF8"));
        
      String result="";
      byte[] temp;
      temp=md5.digest(key.getBytes("UTF8"));
      for (int i=0; i<temp.length; i++){
      result+=Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6);
      

  6.   


            /// <summary>
            /// MD5函数
            /// </summary>
            /// <param name="str">原始字符串</param>
            /// <returns>MD5结果</returns>
            public static string MD5(string str)
            {
                byte[] b = Encoding.Default.GetBytes(str);
                b = new MD5CryptoServiceProvider().ComputeHash(b);
                StringBuilder ret = new StringBuilder();
                for (int i = 0; i < b.Length; i++)
                    ret.Append(b[i].ToString("x").PadLeft(2, '0'));
                return ret.ToString();
            }
      

  7.   

    这个是别人的接口,要加密一起才可以成功!!但是我们平台不是JAVAG
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;public class KeyedDigestMD5 {
        
    public static byte[] getKeyedDigest(byte[] buffer, byte[] key) {
      try {
      MessageDigest md5 = MessageDigest.getInstance("MD5");
      md5.update(buffer);
      return md5.digest(key);
      } catch (NoSuchAlgorithmException e) {
      }
      return null;
      }
    public static String getKeyedDigest(String strSrc, String key) {
      try {
      MessageDigest md5 = MessageDigest.getInstance("MD5");
      md5.update(strSrc.getBytes("UTF8"));
        
      String result="";
      byte[] temp;
      temp=md5.digest(key.getBytes("UTF8"));
      for (int i=0; i<temp.length; i++){
      result+=Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6);
      }
      
      return result;
      
      } catch (NoSuchAlgorithmException e) {
      
      e.printStackTrace();
      
      }catch(Exception e)
      {
      e.printStackTrace();
      }
      return null;
      }
    转为net语言可以了
      

  8.   

    md5算法是一样的,没必要用java的,.net自带md5加密算法或者你直接向供应商要求.net可用的借口
      

  9.   

    你的java转成什么了?你写的.net的又转成什么了?贴个例子
      

  10.   

    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;public class KeyedDigestMD5 {
        
    public static byte[] getKeyedDigest(byte[] buffer, byte[] key) {
      try {
      MessageDigest md5 = MessageDigest.getInstance("MD5");
      md5.update(buffer);
      return md5.digest(key);
      } catch (NoSuchAlgorithmException e) {
      }
      return null;
      }
    public static String getKeyedDigest(String strSrc, String key) {
      try {
      MessageDigest md5 = MessageDigest.getInstance("MD5");
      md5.update(strSrc.getBytes("UTF8"));
        
      String result="";
      byte[] temp;
      temp=md5.digest(key.getBytes("UTF8"));
      for (int i=0; i<temp.length; i++){
      result+=Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6);
      }
      
      return result;
      
      } catch (NoSuchAlgorithmException e) {
      
      e.printStackTrace();
      
      }catch(Exception e)
      {
      e.printStackTrace();
      }
      return null;
      }
    这个是md5是他们接口的!我自己写的MD5验证不能通过!我想把他们把上面这段代码转成net就可以了!!
      

  11.   

    我是说结果,不是你的代码,你输入什么,转成的结果是什么?比如 
    jsp:s = "aaa",MD5(s) = "xxxxx"
    而.net s = "aaa",MD5(s) = "yyyy"各种语言本身都提供了相同的功能