android MD5加密

public class Demo {

	/**
	 * @param args
	 * @throws NoSuchAlgorithmException 
	 */
	public static void main(String[] args) throws NoSuchAlgorithmException {
		MessageDigest digest = MessageDigest.getInstance("md5");
		String password = "123456";
		byte [] bytes =  digest.digest(password.getBytes());
		StringBuffer buffer = new StringBuffer();
		for(byte b: bytes){
			int number = b & 0xff;//加盐
			String hex = Integer.toHexString(number);
			if(hex.length()==1){
				buffer.append("0");
			}
			buffer.append(hex);
		}
		//md5加密后的值
		System.out.println(buffer);

	}

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

你可能感兴趣的:(android,加密,MD5)