You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
832 B

/**
*
*/
package com.ucmed.common.util;
import org.apache.commons.codec.binary.Base64;
/**
* @author John Lee
*
*/
public class Base64Util {
public static String encode(String s) {
try {
s = new String(Base64.encodeBase64(s.getBytes()));
s = s.replace("+", "_");
return s;
} catch (Exception e) {
return s;
}
}
public static String decode(String s) {
try {
s = s.replace("_", "+");
return new String(Base64.decodeBase64(s.getBytes()));
} catch (Exception e) {
return s;
}
}
public static void main(String args[]) {
System.out.println(new Base64Util().encode("石家�));
System.out.println(new Base64Util().decode("55_z5a625bqE"));
}
}