利用java自带的base64实现加密、解密
2014-05-02 17:12
441 查看
package com.stone.util;
import java.io.UnsupportedEncodingException;
import sun.misc.*;
public class Base64 {
// 加密
public static String getBase64(String str) {
byte[] b = null;
String s = null;
try {
b = str.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (b != null) {
s = new BASE64Encoder().encode(b);
}
return s;
}
// 解密
public static String getFromBase64(String s) {
byte[] b = null;
String result = null;
if (s != null) {
BASE64Decoder decoder = new BASE64Decoder();
try {
b = decoder.decodeBuffer(s);
result = new String(b, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
}
import java.io.UnsupportedEncodingException;
import sun.misc.*;
public class Base64 {
// 加密
public static String getBase64(String str) {
byte[] b = null;
String s = null;
try {
b = str.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (b != null) {
s = new BASE64Encoder().encode(b);
}
return s;
}
// 解密
public static String getFromBase64(String s) {
byte[] b = null;
String result = null;
if (s != null) {
BASE64Decoder decoder = new BASE64Decoder();
try {
b = decoder.decodeBuffer(s);
result = new String(b, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
}
相关文章推荐
- 利用java自带的base64实现加密、解密
- 利用java自带的base64实现加密、解密
- 利用java自带的base64实现加密、解密
- 利用java自带的base64实现加密、解密
- 利用java自带的base64实现加密、解密
- 利用java自带的base64实现加密、解密
- 利用Java自带的Base64加密,解密
- java利用Apache commons codec进行MD5加密,BASE64加密解密,执行系统命令
- 基于Java实现的Base64加密、解密原理代码
- java实现BASE64加密和解密
- base64加密与解密Java实现
- Java实现Base64加密解密
- Java RSA加密解密实现方法分析【附BASE64 jar包下载】
- java代码实现对文件的base64加密解密
- Java 实现 Base64 加密解密
- 加密解密算法java实现(1)—BASE64
- JAVA BASE64 加密解密实现代码
- Java实现Base64给文件加密、解密
- java实现Base64加密解密
- JAVA BASE64 加密解密实现代码