JAVA的BASE64編碼與解碼:
1、編碼:
publicstaticString getBASE64(String s) {
if (s == null) returnnull;
return (new sun.misc.BASE64Encoder()).encode( s.getBytes() );
}
2、解碼:
publicstaticString getFromBASE64(String s) {
if (s == null) returnnull;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
returnnewString(b);
} catch (Exception e) {
returnnull;
}
}
posted on 2009-01-06 10:12
蔣家狂潮 閱讀(200)
評論(0) 編輯 收藏 所屬分類:
Basic