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 ...
随机推荐
- C#问答题与附解收集(三)
post.get的区别 答: GET把参数包含在URL中,POST通过request body传递参数.GET请求在URL中传送的参数是有长度限制的,而POST没有.使用post提交的页面在点击[刷新 ...
- 如何从社区的patchwork下载补丁并应用到当前内核源码?
1. 下载 wget http://patchwork.ozlabs.org/series/111111/mbox 2. 打补丁 git am mbox
- js生成带log的二维码(qrcodejs)
github: qrcodejs cdn: http://static.runoob.com/assets/qrcode/qrcode.min.js #qrcode #qrcode margin: 2 ...
- 阶段5 3.微服务项目【学成在线】_day04 页面静态化_18-页面静态化-模板管理-GridFS研究-取文件
需要创建mongoDB的配置类1 配置类里面主要创建.GridFSBucket这个对象.这个对象的作用就是用来打开一个下载流 在cms的微服务下,在config下创建MongoConfig.这个时候就 ...
- iptables之精髓(二)
iptables实际操作 使用-v选项后,iptables为我们展示的信息更多了,那么,这些字段都是什么意思呢?我们来总结一下 pkts:对应规则匹配到的报文的个数. bytes:对应匹配到的报文包的 ...
- failOnMissingWebXml
使用maven创建项目时有时在pom.xml的war处出现failOnMissingWebXml的错误,根据错误提示的原因可以知道项目是web项目,打包时打成war包. 如果项目里没有web.xml, ...
- [!] The version of CocoaPods used to generate the lockfile (1.4.0.beta.1) is higher than the version of the current executable (1.3.0.beta.1). Incompatibility issues may arise.
今天在看一个开源Demo代码的时候,需要执行pod install命令,直接报错如下: 解决方法: 执行:pod update 命令更新资源库即可.
- 【leetcode_easy】557. Reverse Words in a String III
problem 557. Reverse Words in a String III solution1:字符流处理类istringstream. class Solution { public: s ...
- rabbitmq-BasicReject
拒收,是接收端在收到消息的时候响应给RabbitMQ服务的一种命令,告诉服务器不应该由我处理,或者拒绝处理,扔掉.接收端在发送reject命令的时候可以选择是否要重新放回queue中.如果没有其他接收 ...
- HelloCube:ForEach
此示例演示了一个简单的ECS系统,它可以旋转一对立方体. 它显示了什么? 此示例演示了ECS中数据和功能的分离.数据存储在组件中,如下RadiansPerSecond属性存储在RotationSpee ...