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的更多相关文章

  1. node_nibbler:自定义Base32/base64 encode/decode库

    https://github.com/mattrobenolt/node_nibbler 可以将本源码复制到自己需要的JS文件中,比如下面这个文件,一个基于BASE64加密请求参数的REST工具: [ ...

  2. Base64 encode/decode large file

    转载:http://www.cnblogs.com/jzywh/archive/2008/04/20/base64_encode_large_file.html The class System.Co ...

  3. javascript base64 encode decode 支持中文

    * 字符编码 ** 一定要知道数据的字符编码 ** 使用utf-8字符编码存储数据 ** 使用utf-8字符编码输出数据 * Crypto.js 支持中文 Base64编码说明 Base64编码要求把 ...

  4. java URLEncoder 和Base64.encode()

    参考: http://www.360doc.com/content/10/1103/12/1485725_66213001.shtml (URLEncode) http://blog.csdn.net ...

  5. python中文处理之encode/decode函数

    python中文处理相信迷惑过不少同学.下面说说python2/3的encode和decode函数. python2中,使用decode()和encode()来进行解码和编码,以unicode类型作为 ...

  6. python编码问题之\"encode\"&\"decode\"

    python encode decode 编码 decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换 ...

  7. python编码encode decode(解惑)

    关于python 字符串编码一直没有搞清楚,今天总结了一下. Python 字符串类型 Python有两种字符串类型:str 与 unicode. 字符串实例 # -*- coding: utf-8 ...

  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 ...

  9. python3.3 unicode(encode&decode)

    最近在用python写多语言的一个插件时,涉及到python3.x中的unicode和编码操作,本文就是针对编码问题研究的汇总,目前已开源至github.以下内容来自项目中的README. 1 ASC ...

随机推荐

  1. Centos 6 can't found command subscription-manager

    [root@localhost ~]# subscription-manager: command not found-bash: -bash:: command not found resoluti ...

  2. Angular4.x+Ionic3 踩坑之路之打包时出现JAVASCRIPT HEAP OUT OF MEMORY的几种解决办法

    最近开发的一个比较大型的App时打生产环境包是出现内存不足导致打包失败的问题.然后百度发现解决方法都是一样,自己试了一下都没什么暖用,心里只想用呵呵来形容了.最后经朋友介绍,技术问题还得去谷歌,git ...

  3. RabbitMQ交换器的类型

    RabbitMQ常用的交换器类型有:fanout,direct,topic,headers fanout它会把所有发送到该交换器的消息路由到所有与该交换器绑定的队列中. direct它会把消息路由到哪 ...

  4. Oracle中shrink space命令

    shrink_clause:   http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_3001.htm#i2192484 ...

  5. ios 自动去重

      //resultArrM 数据原//_indexArray 过滤后的数据//MYSelectAreaModel 模型 /* 重定义索引 */ - (void)sy_indexArray{ /* 索 ...

  6. mvn安装

    先安装jdk.jre,maven需要jdk.jre支持 1.安装 jdk 卸载自带jdk rpm -qa | grep jdk rpm -e --nodeps 下载 JDK JDK 下载地址:http ...

  7. QFramework 使用指南 2020 (四):脚本生成(2)ViewController 与 ViewController 嵌套绑定

    在上一篇,我们学习了,脚本生成的基本使用. 在这一篇,我们试着深入,聊聊脚本生成给我们带来的便利. 脚本生成的便利 首先,我们要知道,在 Unity 的游戏世界中都是以 GameObject 为单位的 ...

  8. 【Qt开发】Qt5 中对 C++11 一些新特性的封装

    C++11 是现在的 C++ 标准的名称,C++11 为 C++ 语言带来很多新特性. 而 Qt 4.8 是 Qt 首个在其 API 中开始使用一些新的 C++11 特性的版本,我之前写过一篇博文:C ...

  9. stat中的st_dev和st_rdev

    目录 stat中的st_dev和st_rdev title: stat中的st_dev和st_rdev date: 2019/11/27 21:04:25 toc: true --- stat中的st ...

  10. 巧用 Class Extension 隐藏属性

    一般来说,Extension用来给Class增加私有属性和方法,写在 Class 的.m文件.但是Extension不是必须要写在.m文件,你可以写在任何地方,只要在 @implementation  ...