实现字符串的加密

package com.tarena.dang.util;

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

import sun.misc.BASE64Encoder;

public class DigestUtil {
	public static String digest(String seq) throws NoSuchAlgorithmException{
		//获得md5算法的工具类,单向加密
		MessageDigest digest=MessageDigest.getInstance("md5");
		byte[] temp=digest.digest(seq.getBytes());
		BASE64Encoder encode=new BASE64Encoder();
		seq=encode.encode(temp);
		return seq;
	}
	public static void main(String[] args) throws NoSuchAlgorithmException {
		String s="sssss";
		DigestUtil util=new DigestUtil();
		System.out.println(util.digest(s));
	}
}

你可能感兴趣的:(加密,字符串)