MD5+SHA+BASE64加密

//一般用于校验软件是否被修改
package demo;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class demo1 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  try {
   String pwd="jfalfdjalfjaldfajdlajfdl";
   MessageDigest md=MessageDigest.getInstance("MD5");
   MessageDigest md2=MessageDigest.getInstance("SHA");
    byte[] s=md.digest(pwd.getBytes());
    byte[] s2=md2.digest(pwd.getBytes());
    BASE64Encoder be=new BASE64Encoder();
    System.out.println(be.encode(s));//md5+base64单向加密不可逆 md5信息摘要加密算法
    System.out.println(be.encode(s2));//SHA+base64单向加密算法不可逆 SHA安全散列算法比MD5更安全
    
  } catch (NoSuchAlgorithmException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}


你可能感兴趣的:(base64)