首页 > 编程 > Java > 正文

Java中的Base64加解密方法

2019-11-11 06:14:28
字体:
来源:转载
供稿:网友
更多技术文章可以访问我的个人博客 www.rainweb.site

Base加密方法很方便,在保存一些特别数据时可以直接调用方法进行加密和解密的操作,我会发一篇专门介绍base64原理的文章,有兴趣的可以去我的个人博客里查看。

下面是使用java进行base64加密与解密的源码,使用时在java项目中新建一个类,然后将代码挂上,在外部加密或解密直接实例化类,再调用响应函数即可,记住值的传递与接收

public static String encodeBase64(String cleartext) {// TODO Auto-generated method stubtry {cleartext = new String(Base64.encodeBase64(cleartext.getBytes("UTF-8")));} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.PRintStackTrace();}return cleartext;}Base解密public static String decodeBase64(String ciphertext){try {ciphertext = new String(Base64.decodeBase64(ciphertext.getBytes()),"UTF-8");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}return ciphertext;}

更多技术文章可以访问我的个人博客 www.rainweb.site


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表