zoukankan      html  css  js  c++  java
  • 每日必读(2) --Base64

    一、 base64是什么?

    按照RFC2045的定义,Base64被定义为:Base64内容传送编码被设计用来把任意序列的8位字节描述为一种不易被人直接识别的形式。(The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable.)

    使用的字符包括大小写字母各26个,加上10个数字,和加号“+”,斜杠“/”,一共64个字符,等号“=”用来作为后缀用途。

    二、 base64的作用

    1. 实现简单的数据加密,使用户一眼望去完全看不出真实数据内容,base64算法的复杂程度要小,效率要高相对较高。
    2. 某些系统或应用,只能使用ASCII字符,例如Email,需使用base64对数据进行编码

    以上内容摘自http://www.cnblogs.com/apm70/articles/2358569.html

    三、base64原理

    Base64要求把每三个8Bit的字节转换为四个6Bit的字节(3*8 = 4*6 = 24),然后把6Bit再添两位高位0,组成四个8Bit的字节,也就是说,转换后的字符串理论上将要比原来的长1/3。编码原理如下所示:

    (1)base64的编码都是按字符串长度,以每3个8bit的字符为一组,

    (2)然后针对每组,首先获取每个字符的ASCII编码,

    (3)然后将ASCII编码转换成8bit的二进制,得到一组3*8=24bit的字节

    (4)然后再将这24bit划分为4个6bit的字节,并在每个6bit的字节前面都填两个高位0,得到4个8bit的字节

    (5)然后将这4个8bit的字节转换成10进制,对照Base64编码表,得到对应编码后的字符。

    四、base64字符映射表

    五、base64例程

                // 一个字节
                byte []  b = new byte [] { 0x01};
                string s = Convert.ToBase64String(b,0,1);
                byte [] be = Convert.FromBase64String(s);
    
                // 两个字节
                byte[] bs = new byte[] { 0x01,0x02};
                string ss = Convert.ToBase64String(bs, 0, 2);
    
                // 三个字节
                byte[] bss = new byte[] { 0x01, 0x02,0x03 };
                string sss = Convert.ToBase64String(bss, 0, 3);
  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/panpeng666/p/4333380.html
Copyright © 2011-2022 走看看