JAVA_BASE64加密和解密

import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;



	public class BASE64Coding { 
		private static BASE64Encoder encoder = new sun.misc.BASE64Encoder(); 
		private static BASE64Decoder decoder = new sun.misc.BASE64Decoder(); 
		public BASE64Coding() {} 
		public static String encode (String s)
		{ 
			return encoder.encode(s.getBytes());
			} 
		public static String decode (String s){ 
			try {
				byte[] temp = decoder.decodeBuffer(s);
				return new String(temp);
				} catch (IOException ioe) { 
					// handler
				}
			return s;
		}

																																																																																																		// exception
																																																																																																		// here}
																																																																																																		// return
																																																																																																		// null;}}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String str="13516741234";
		System.out.println("加密");
		System.out.println(BASE64Coding.encode(str));
		System.out.println("解密");
		System.out.println(BASE64Coding.decode(BASE64Coding.encode(str)));

	}

}

 

你可能感兴趣的:(java,sun)