---
title: "BASE64对字符串的加密（解密）方法"
author: "Pringles"
date: "2007-04-29T13:50:37Z"
tags: []
slug: "base64"
draft: false
lastmod: "2007-04-29T13:50:37Z"
id: 76089
url: "https://pringles.iteye.com/blog/76089"
---

<%@ page import="sun.misc.BASE64Decoder" %>
<%@ page import="sun.misc.BASE64Encoder" %>




// 将 s 进行 BASE64 编码 
　　 static String getBASE64(String s) { 
　　    if (s == null) return null; 
　　    return (new sun.misc.BASE64Encoder()).encode( s.getBytes() ); 
　　} 
　　
　　// 将 BASE64 编码的字符串 s 进行解码 
　　static String decodeBASE64(String ss) {
		BASE64Decoder decoder = new BASE64Decoder(); 
		if(ss == null){
			return null;
		}else{
			try{
			byte b = decoder.decodeBuffer(ss); 
			return new String(b);
			}catch(Exception e){
				return null;
			}
		}
	}
　　}