Java 对字符串数据进行MD5/SHA1哈希散列运算

Java 对字符串数据进行MD5/SHA1哈希散列运算


package cn.aibo.test;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class TestMd5AndSha1 {
	
	public static String md5(String data) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(data.getBytes());
		StringBuffer buf = new StringBuffer();
		byte[] bits = md.digest();
		for(int i=0;i

运算结果

1 MD5 : 900150983cd24fb0d6963f7d28e17f72
2 SHA1 : a9993e364706816aba3e25717850c26c9cd0d89d

你可能感兴趣的:(JAVA,ANDROID)