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 ...
随机推荐
- Spring事务知识点
事务的传播属性 PROPAGATION_REQUIRED 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中.// 最常用,@Transactional注解默认 PROPAGA ...
- Linux下R环境安装
R环境的两种安装方式,源码编译安装和yum在线安装 第一种:源码编译安装 1.首先,从官网上下载3.5.0版本 2.下载完后记得解压,我的习惯是解压在/usr/local下面 tar -zxvf R- ...
- JAVA通过FTP方式向远程服务器或者客户端上传、下载文件,以及删除FTP服务器上的文件
1.在目标服务器上搭建FTP服务器 搭建方式有多种大家可以自行选择,例如使用Serv-U或者FTPServer.exe:这里我以FTPServer.exe为例搭建:在目标服务器(这里对应的IP是10. ...
- SQL-W3School-高级:SQL VIEW(视图)
ylbtech-SQL-W3School-高级:SQL VIEW(视图) 1.返回顶部 1. 视图是可视化的表. 本章讲解如何创建.更新和删除视图. SQL CREATE VIEW 语句 什么是视图? ...
- hTTP的URL编码
使用jdk提供的类完成URL的编解码 public class UrlDemo { public static void main(String[] args) throws Exception { ...
- ubuntu 安装的一些软件
https://github.com/wszqkzqk/deepin-wine-ubuntu 14 版本的ubuntu 安装发生问题; 16 18 的都可以安装成功微信;
- 微信小程序的target和currentTarget的区别
https://www.jb51.net/article/160886.htm 在小程序的事件回调触发时,会接收一个事件对象,事件对象的参数中包含一个target和currentTarget属性,接下 ...
- Oracle中替换字符中空格、制表符、换行符、回车符
引用:https://blog.csdn.net/linminqin/article/details/7386510 特殊符号ascii定义 制表符 chr(9) 换行符 chr(10) 回车符 c ...
- linux下使用openssl和md5sum加密文件或者字符串
#openssl //在终端中输入openssl后回车. OpenSSL> md5 //输入md5后回车 123456 //接着输入123456,不要输入回车.然后按3次ctr ...
- 搭建IIS CA DC Exchange TMG SQL (CA DC篇)
搭建IIS CA DC Exchange TMG SQL (CA DC篇) 步骤 1: 在“下一步(N) > (按下按钮)”(位于“添加角色向导”中)上用户左键单击 步骤 2: 在“Ac ...