对url加密的加密解密算法,这样的加密结果只有数字和字母
2016-12-09 14:29
501 查看
package com.jubaopen.base.util;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* 对url加密的加密解密算法,这样的加密结果只有数字和字母
* @author Administrator
*
*/
public class Base64EncodingUtil {
private static final BASE64Decoder decoder = new BASE64Decoder();
private static final BASE64Encoder encoder = new BASE64Encoder();
private static final Base64 base64 = new Base64();
/**
* BASE64加密
*
* @param key
* @return
* @throws Exception
*/
public static String encryptBASE64(String key) throws Exception {
if (key == null || key.length() < 1) {
return "";
}
//return new String(encoder.encode(key.getBytes()));
return new String(base64.encodeBase64URLSafe((new String(encoder.encode(key.getBytes()))).getBytes()));
}
public void changeCodeGBK(){
}
/**
* BASE64解密
*
* @param key
* @return
* @throws Exception
*/
public static String decryptBASE64(String key) throws Exception {
if (key == null || key.length() < 1) {
return "";
}
return new String(decoder.decodeBuffer(new String(base64.decodeBase64(key.getBytes()))));
//return new String(base64.decodeBase64(key.getBytes()));
}
public static void main(String[] args) throws Exception {
String s=Base64EncodingUtil.encryptBASE64("dddd");
System.out.println(s);
System.out.println(Base64EncodingUtil.decryptBASE64(s));
}
}
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* 对url加密的加密解密算法,这样的加密结果只有数字和字母
* @author Administrator
*
*/
public class Base64EncodingUtil {
private static final BASE64Decoder decoder = new BASE64Decoder();
private static final BASE64Encoder encoder = new BASE64Encoder();
private static final Base64 base64 = new Base64();
/**
* BASE64加密
*
* @param key
* @return
* @throws Exception
*/
public static String encryptBASE64(String key) throws Exception {
if (key == null || key.length() < 1) {
return "";
}
//return new String(encoder.encode(key.getBytes()));
return new String(base64.encodeBase64URLSafe((new String(encoder.encode(key.getBytes()))).getBytes()));
}
public void changeCodeGBK(){
}
/**
* BASE64解密
*
* @param key
* @return
* @throws Exception
*/
public static String decryptBASE64(String key) throws Exception {
if (key == null || key.length() < 1) {
return "";
}
return new String(decoder.decodeBuffer(new String(base64.decodeBase64(key.getBytes()))));
//return new String(base64.decodeBase64(key.getBytes()));
}
public static void main(String[] args) throws Exception {
String s=Base64EncodingUtil.encryptBASE64("dddd");
System.out.println(s);
System.out.println(Base64EncodingUtil.decryptBASE64(s));
}
}
相关文章推荐
- PHP加密解密类(密文只有大小写字母和数字),支持中文加密
- 针对url参数的加密解密算法(原创)
- PHP加密解密数字,适用于URL加密。
- 百度音乐url加密及解密算法
- html简单 字母数字 加密 解密 实例
- 纯数字加密和解密算法(原创)
- 电报加密 描述: 发送电报保密是一项重要的工作,尤其是在军事领域,所以,为了安全的需要常常会对发送的内容进行加密,然后,接收方再进行解密,这样就达到了安全的需要。 本次我们完成一个简单的对字母加密程
- 针对url参数的加密解密算法(原创)
- 使用Spring AOP对url参数进行解密以及对返回结果进行加密
- URL 传值 加密 解密 算法
- 加密解密信息摘要算法搜集
- WEB系统中加密/解密URL传输参数
- 加密解密、信息摘要算法收集
- 跨语言平台的RSA加密、解密、签名、验证算法的实现
- 加密解密Url的类
- SAM的散列存储加密解密算法以及SYSKEY的计算
- 游戏封包的加密与解密算法的破解
- 提供一个基于.NET的加密/解密算法[转.CNSDN.com.cn]
- [★]基于.NET 的 加密 解密 算法总结[一]
- 加密解密、信息摘要算法收集