BASE64 Encode Decode
package com.humi.encryption;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* @since 2017年8月3日10:14:00
* @author Penny
* @category 加解密 BASE64Encoder BASE64Decoder;
*/
public class EncryptionTest {
public static void main(String[] args) {
String words1 = "this is a test words by 2017年8月3日10:16:24";
String words2 = "你看的全是乱码!QQAQ!";
// StringBuilder sb;
BASE64Encoder enc = new BASE64Encoder();
BASE64Decoder dec = new BASE64Decoder();
try {
words1 = enc.encode(words1.getBytes("utf-8"));
words2 = enc.encode(words2.getBytes("utf-8"));
System.out.println("===========编码后===========");
System.out.println(words1);
System.out.println(words2);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
words1 = new String(dec.decodeBuffer(words1),"utf-8");
words2 = new String(dec.decodeBuffer(words2),"utf-8");
System.out.println("===========解码后===========");
System.out.println(words1);
System.out.println(words2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,在发送电子邮件时,服务器认证的用户名和密码需要用Base64编码,附件也需要用Base64编码。
Base64要求把每三个8Bit的字节转换为四个6Bit的字节(3*8 = 4*6 = 24),然后把6Bit再添两位高位0,组成四个8Bit的字节,也就是说,转换后的字符串理论上将要比原来的长1/3。
原文的字节最后不够3个的地方用0来补足,转换时Base64编码用=号来代替。这就是为什么有些Base64编码会以一个或两个等号结束的原因,但等号最多只有两个。
``
BASE64 Encode Decode的更多相关文章
- node_nibbler:自定义Base32/base64 encode/decode库
https://github.com/mattrobenolt/node_nibbler 可以将本源码复制到自己需要的JS文件中,比如下面这个文件,一个基于BASE64加密请求参数的REST工具: [ ...
- Base64 encode/decode large file
转载:http://www.cnblogs.com/jzywh/archive/2008/04/20/base64_encode_large_file.html The class System.Co ...
- javascript base64 encode decode 支持中文
* 字符编码 ** 一定要知道数据的字符编码 ** 使用utf-8字符编码存储数据 ** 使用utf-8字符编码输出数据 * Crypto.js 支持中文 Base64编码说明 Base64编码要求把 ...
- java URLEncoder 和Base64.encode()
参考: http://www.360doc.com/content/10/1103/12/1485725_66213001.shtml (URLEncode) http://blog.csdn.net ...
- python中文处理之encode/decode函数
python中文处理相信迷惑过不少同学.下面说说python2/3的encode和decode函数. python2中,使用decode()和encode()来进行解码和编码,以unicode类型作为 ...
- python编码问题之\"encode\"&\"decode\"
python encode decode 编码 decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换 ...
- python编码encode decode(解惑)
关于python 字符串编码一直没有搞清楚,今天总结了一下. Python 字符串类型 Python有两种字符串类型:str 与 unicode. 字符串实例 # -*- coding: utf-8 ...
- (转)Integrating Intel® Media SDK with FFmpeg for mux/demuxing and audio encode/decode usages 1
Download Article and Source Code Download Integrating Intel® Media SDK with FFmpeg for mux/demuxing ...
- python3.3 unicode(encode&decode)
最近在用python写多语言的一个插件时,涉及到python3.x中的unicode和编码操作,本文就是针对编码问题研究的汇总,目前已开源至github.以下内容来自项目中的README. 1 ASC ...
随机推荐
- linux下的usb抓包方法
1 linux下的usb抓包方法1.配置内核使能usb monitor: make menuconfig Device Drivers --> ...
- <JavaScript> call()、apply()、bind() 的用法
其实是一个很简单的东西,认真看十分钟就从一脸懵B 到完全 理解! 先看明白下面: 例 1 obj.objAge; obj.myFun() // 小张年龄 undefined 例 2 shows() ...
- PAT 甲级 1020 Tree Traversals (25 分)(二叉树已知后序和中序建树求层序)
1020 Tree Traversals (25 分) Suppose that all the keys in a binary tree are distinct positive integ ...
- maven编译正常,运行报错:中没有主清单属性
在pom.xml添加插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId&g ...
- JAVA 基础编程练习题19 【程序 19 打印菱形图案】
19 [程序 19 打印菱形图案] 题目:打印出如下图案(菱形) * *** ************ ***** *** * 程序分析:先把图形分成两部分来看待,前四行一个 ...
- Swift中添加标记(MARK)和警告(TODO FIXME)
//MARK: - 注释说明 //FIXME: - 表示此处有bug 或者要优化 //TODO: - 一般用于写到哪了 做个标记,让后回来继续 开启警告: 参考博客: http://blog.csd ...
- 不要在viewWillDisappear:方法中移除通知
都知道viewWillAppear:方法是在控制器的view将要显示的时候调用的,而viewWillDisappear:方法是在控制器的view将要隐藏的时候调用. 这看上去没什么问题,键盘的显示和隐 ...
- Spring Aop(十)——编程式的Pointcut
转发地址:https://www.iteye.com/blog/elim-2396526 编程式的Pointcut 除了可以通过注解和Xml配置定义Pointcut之外,其实我们还可以通过程序来定义P ...
- Eclipse阿里代码规范插件安装,卸载与使用
使用阿里代码规范插件,我们就可以查看我们写的代码是否规范了 找到阿里代码插件网址: 网址:https://p3c.alibaba.com/plugin/eclipse/update/ 打开我们的网址, ...
- KMP --关于cogs1570 乌力波
题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=vQzXJkgWa [题目描述] 法国作家乔治·佩雷克(Georges Perec,193 ...