ITPub博客

首页 > 应用开发 > IT综合 > get string MD5

get string MD5

原创 IT综合 作者:oxoxooxx 时间:2011-09-09 16:26:08 0 删除 编辑
import java.io.*;
import java.util.*;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

class cassandraMD5{
static final Scanner cin=new Scanner(System.in);

public static byte[] hash(String type, byte[]... data){
byte[] result = null;
try{
MessageDigest messageDigest = MessageDigest.getInstance(type);
for(byte[] block : data)
messageDigest.update(block);
result = messageDigest.digest();
}
catch (Exception e){
throw new RuntimeException(e);
}
return result;
}

public static BigInteger hash(String data){
byte[] result = null;
try {
result = hash("MD5", data.getBytes("UTF8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BigInteger hash = new BigInteger(result);
return hash.abs();
}

public static void main(String[] args){
while(cin.hasNext()){
String str1=cin.next();
BigInteger a= hash(str1);
System.out.println(a);
}
BigInteger a= hash(str2);
System.out.println(a);
}
}[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23937368/viewspace-1054900/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    178
  • 访问量
    843646