首页| 新闻| 科技| 人物| 科学| 话题| 运营| 设计| 开发| 服务器| 学院| 产品| 网文| 娱乐| 游戏| 图片
本文实例为大家分享了java使用Base64编码的具体代码,供大家参考,具体内容如下
Test Base64
package com.weiwen.provider.utils;import java.io.IOException;import com.alibaba.fastjson.JSON;import lombok.extern.slf4j.Slf4j;import org.junit.Test;import sun.misc.BASE64Encoder;import sun.misc.BASE64Decoder;@Slf4jpublic class Base64 { @Test public void testBase64() throws IOException { // BASE64编码 String s = "1f2bc1970a2eb19aabc0f94acea922717a1ae998603ff0593baff"; BASE64Encoder encoder = new BASE64Encoder(); s = encoder.encode(s.getBytes("UTF-8"));// System.out.println(s); log.info("BASE64编码为:{}", JSON.toJSONString(s)); // BASE64解码 BASE64Decoder decoder = new BASE64Decoder(); byte[] bytes = decoder.decodeBuffer(s);// System.out.println(new String(bytes, "UTF-8")); log.info("BASE64解码为:{}", JSON.toJSONString(new String(bytes, "UTF-8"))); } }
Base64工具类
package com.weiwen.provider.utils;import java.io.IOException;import com.alibaba.fastjson.JSON;import lombok.extern.slf4j.Slf4j;import org.junit.Test;import sun.misc.BASE64Encoder;import sun.misc.BASE64Decoder;@Slf4jpublic class Base64 { /** * Base64 编码 * @param encodeText * @return * @throws IOException */ public static String base64Encode(String encodeText) throws IOException{ BASE64Encoder encoder = new BASE64Encoder(); String str = encoder.encode(encodeText.getBytes("UTF-8")); log.info("BASE64编码为:{}", JSON.toJSONString(str)); return str; } /** * Base64 解码 * @param decodeText * @return * @throws IOException */ public static byte[] base64Decode(String decodeText) throws IOException{ BASE64Decoder decoder = new BASE64Decoder(); byte[] bytes = decoder.decodeBuffer(decodeText); log.info("BASE64解码为:{}", JSON.toJSONString(new String(bytes, "UTF-8"))); return bytes; }}
以上所述是小编给大家介绍的java使用Base64编码详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对CuoXin错新网网站的支持!
phpwind9.0系统的视觉进化论(
phpwind 的编码错误导致cookie
phpwind的rewrite重写原理
南国有佳人,容华若桃李
怀念青春,憧憬着自己的美好未来
中国旅游景点集锦 美丽的风景
名胜古迹风景 最美的景色
路边摊小吃 酒香不怕巷子深
特色路边摊小吃 下班路上的一道美食
爷爷都是从孙子走过来的
我太帅了,睡不着咋整啊
新闻热点
疑难解答
图片精选
利用Spring boot如何创建简单的web
Spring boot学习教程之快速入门篇
Spring boot实现热部署的两种方式
Spring中属性注入的几种方式以及复
网友关注