使用Apache commons codec类Base64进行加密解密

maven依赖

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
</dependency>

代码实现

package com.ljq.durian.common.util;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger; /**
* Base64加密解密工具类
*
* @author jqlin
*/
public class Base64Util {
private static final Logger logger = Logger.getLogger(Base64Util.class);
private static final String charset = "utf-8"; /**
* 解密
*
* @param data
* @return
* @author jqlin
*/
public static String decode(String data) {
try {
if (null == data) {
return null;
} return new String(Base64.decodeBase64(data.getBytes(charset)), charset);
} catch (UnsupportedEncodingException e) {
logger.error(String.format("字符串:%s,解密异常", data), e);
} return null;
} /**
* 加密
*
* @param data
* @return
* @author jqlin
*/
public static String encode(String data) {
try {
if (null == data) {
return null;
}
return new String(Base64.encodeBase64(data.getBytes(charset)), charset);
} catch (UnsupportedEncodingException e) {
logger.error(String.format("字符串:%s,加密异常", data), e);
} return null;
} }

Base64加密解密工具类的更多相关文章

  1. 使用jframe编写一个base64加密解密工具

    该工具可以使用exe4j来打包成exe工具(如何打包自己百度) 先上截图功能 运行main方法后,会弹出如下窗口 输入密文 然后点击解密,在点格式化 代码分享 package tools;import ...

  2. .Net(c#)加密解密工具类:

    /// <summary> /// .Net加密解密帮助类 /// </summary> public class NetCryptoHelper { #region des实 ...

  3. 加密解密工具类(Java,DES)

    一个Java版的DES加密工具类,能够用来进行网络传输数据加密,保存password的时候进行加密. import java.security.Key; import java.security.sp ...

  4. AES加密解密工具类封装(AESUtil)

    package club.codeapes.common.utils; import org.springframework.util.Base64Utils; import javax.crypto ...

  5. java 加密解密工具类(实用!!!)

    最近发现了一个加密解密的好例子,很方便使用,可以作为平时开发的工具集,记录一下. package com.sh.springboottdemo2.util; import com.sun.org.ap ...

  6. java加密解密工具类

    package com.founder.mrp.util; import java.nio.charset.StandardCharsets; import java.security.Key; im ...

  7. des 加密解密工具类

    最近在做des的双对称加密解密,特此记录一下. des对称加密,是一种比较传统的加密方式,其加密运算.解密运算使用的是同样的密钥,信息的发送者和信息的接收者在进行信息的传输与处理时,必须共同持有该密码 ...

  8. base加密解密工具类

    public class MLDUtil { public static Key DEFAULT_KEY = null; public static final String DEFAULT_SECR ...

  9. ios 加密解密工具类字符判断等

    #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface Helpers : NSObject ...

随机推荐

  1. (线段树) Count the Colors --ZOJ --1610

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...

  2. 【spfa训练】HDU4725 (层级建图)

    HDU4725 题目大意:一些节点分布在不同的层上,已知相邻的层可以往来距离为c,在给你一些已知的边,问你点1-n的最短路 分析:越往后做,越觉得最短路的考点已经不是spfa算法还是dijkscar算 ...

  3. Why I Want A Wife

    I want a wife who will take care of my physical needs. I want a wife who will keep my house clean. A ...

  4. netty--NioEventLoop滴干活

    netty是最近项目要用到的nio框架,找了各种资料,发现称赞它的有点多,所以决定用它:其实也就二选一嘛,mina或netty或自己写.对于mina,也不熟,不过看各种介绍,貌似netty干活还是很不 ...

  5. LeetCode140:Word Break II

    题目: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where e ...

  6. LeetCode139:Word Break

    题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-se ...

  7. Chrome自定义缩放百分比

    我想要设置Chrome页面缩放为120%,但是Chrome只提供110% 125%,根本没有让我舒心的缩放比例. 强迫症发作,谷歌了半天没有一个很好的解决方案. 虽然也有不少第三方扩展可以自定义缩放比 ...

  8. Layui 手册一

    icon-图标 1:√2:×3:问号4:锁5:哭脸6:笑脸7:感叹号 使用layer.msg('',{ icon:1 });  目前只提供7种图标可选,用的适当还是很好看的. 表格刷新 parent. ...

  9. CryptoJS与C#AES加解密互转

    CryptoJS下载地址: https://code.google.com/archive/p/crypto-js/downloads http://download.csdn.net/detail/ ...

  10. 开源且功能强大的C# 扩展方法类库Pure.Ext,包含1000+个拓展方法 (支持.Net Framework和.Net Core)

    先上地址 Github: https://github.com/purestackorg/pure.ext Gitee: https://gitee.com/purestack/pure.ext 扩展 ...