import java.security.*; 
import java.security.spec.*; 
public class PieChart
{
public final static void main(String arg[])

char hexDigits[] = { 
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 
'e', 'f'}; 
String s="123456";
try
{
byte[] strTemp = s.getBytes(); 
MessageDigest mdTemp = MessageDigest.getInstance("MD5"); 
mdTemp.update(strTemp); 
byte[] md = mdTemp.digest(); 
int j = md.length; 
char str[] = new char[j * 2]; 
int k = 0; 
for (int i = 0; i < j; i++) 

byte byte0 = md[i]; 
str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 
str[k++] = hexDigits[byte0 & 0xf];



}
catch(Exception e){}

}
}  连输出都没有,不知道是实现什么的

解决方案 »

  1.   

    貌似对s做了一下MD5编码,然后自己又进行了某种编码,这个应该是示例代码,str就是输出了,s是输入。
      

  2.   

    System.out.println(new String(str));这样就可以输出“123456”的 MD5 散列加密的 32 位密文了。
      

  3.   

    一般不是这样写的啦,我原来写过一个可以参考一下:第一个参数是原文,第二个参数是算法名称主要有(MD2、MD5、SHA-1、SHA-256、SHA-512)/**
     * encrypted password based on JCA algorithm of message digest 
     * @param plainText orginal password text
     * @param algorithm name of algorithm
     * @return encrypted password
     */
    public static String encrypte(String plainText, String algorithm) {
      MessageDigest md = null;
      try {
        md = MessageDigest.getInstance(algorithm);
      } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
      }
      md.update(plainText.getBytes());
      byte[] b = md.digest();
      StringBuffer output = new StringBuffer();
      for(int i = 0; i < b.length; i++) {      
        String temp = Integer.toHexString(b[i] & 0xff);
        if(temp.length() < 2){
          output.append("0");
        }
        output.append(temp);
      }
      return output.toString();
    }