/**
* BASE64加密
* @param str
* @return
*/
public static String encodePasswordByBASE64(String str)
{
BASE64Encoder b = new BASE64Encoder();
String res = b.encode(str.getBytes());
return res;
}
/**
* BASE64解密
* @param str
* @return
*/
public static String decodePasswordByBASE64(String str)
{
BASE64Decoder bd = new BASE64Decoder();
byte[] bt=null;
try {
bt = bd.decodeBuffer(str);
} catch (IOException e) {
e.printStackTrace();
}
String res = new String(bt);
return res;
}
用法:
public static void main(String[] args)
{
String pwd="123";
System.out.println("加密:"+encodePasswordByBASE64(pwd));
String enstr="MTIz";
System.out.println("解密:"+decodePasswordByBASE64(enstr));
}