美文网首页
Base64编码

Base64编码

作者: sylviaMo | 来源:发表于2017-11-24 17:13 被阅读65次

简述

Base64常用于在通常处理文本数据的场合,表示、传输、存储一些二进制数据。

flag meaning
DEFAULT Encoder/Decoder flag,RFC 2045
NO_PADDING Encoder flag bit to omit the padding '=' characters at the end of the output (if any).
NO_WRAP Encoder flag bit to omit all line terminators(i.e., the output will be on one long line).
CRLF Encoder flag bit to indicate lines should be terminated with a CRLF pair instead of just an LF. Has no effect if NO_WRAP is specified as well.
URL_SAFE Encoder/decoder flag bit to indicate using the "URL and filename safe" variant of Base64 (see RFC 3548 section 4) where - and _ are used in place of + and*.
NO_CLOSE Flag to pass to Base64OutputStream to indicate that it should not close the output stream it is wrapping when it itself is closed.

Base64编码提供以下几种flag:

flag meaning
DEFAULT Encoder/Decoder flag,RFC 2045
NO_PADDING Encoder flag bit to omit the padding '=' characters at the end of the output (if any).
NO_WRAP Encoder flag bit to omit all line terminators(i.e., the output will be on one long line).
CRLF Encoder flag bit to indicate lines should be terminated with a CRLF pair instead of just an LF. Has no effect if NO_WRAP is specified as well.
URL_SAFE Encoder/decoder flag bit to indicate using the "URL and filename safe" variant of Base64 (see RFC 3548 section 4) where - and _ are used in place of + and*.
NO_CLOSE Flag to pass to Base64OutputStream to indicate that it should not close the output stream it is wrapping when it itself is closed.

在Base64中的可打印字符包括字母A-Z、a-z、数字0-9,这样共有62个字符,最后两个可打印符号在不同的系统中而不同。

转换的时候,将三个byte的数据,先后放入一个24bit的缓冲区中,先来的byte占高位。数据不足3byte的话,于缓冲器中剩下的bit用0补足。然后,每次取出6(因为26=64)个bit,按照其值选择ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/中的字符作为编码后的输出。不断进行,直到全部输入数据转换完成。

当原数据长度不是3的整数倍时, 如果最后剩下一个输入数据,在编码结果后加2个“=”;如果最后剩下两个输入数据,编码结果后加1个“=”;如果没有剩下任何数据,就什么都不要加


base64.png

因为URL编码器会把标准Base64中的“/”和“+”字符变为形如“%XX”的形式,而这些“%”号在存入数据库时还需要再进行转换,因为ANSI SQL中已将“%”号用作通配符。

为解决此问题,可采用一种用于URL的改进Base64编码,它不在末尾填充'='号,并将标准Base64中的“+”和“/”分别改成了“-”和“_”,这样就免去了在URL编解码和数据库存储时所要作的转换,避免了编码信息长度在此过程中的增加,并统一了数据库、表单等处对象标识符的格式。

相关文章

  • iOS URL安全的Base64编码、解码

    参考iOS开发探索-Base64编码iOS URL编码&base64编码URL安全的Base64编码,解码 为什么...

  • BASE64 编码简析

    Base64编码: <1>·Base64编码简介: <2>·使用Base64的原因: <3>·编码原理: 成这个字...

  • SMTP整理

    账号:BASE64编码的账号 密码:BASE64编码的密码 快速BASE64编码网址: http://tools....

  • base64 和 url base64 和 encodeURIC

    1 先来看base64编码 2 再看url base64编码 可以看出,非url base64不会对斜杠进行编码。...

  • Base系列加密解密

    Base编码系列:[Base64][Base32] [Base16] [Base64] Base64编码是使用64...

  • java android 对接接口加密

    加密方式 方案1 使用Base64编码最常用的就是Base64编码了,Base64不算是加密,只是把字符经过编码变...

  • Base64

    Base64简介 Base64 原理解析 编码实现 Base64简介 命令行运行base64编码和解码 对文件操作...

  • base64编码解码原理散图

    base64编码出现原因: base64转码原理000.png base64编码原理: base64转码原理.pn...

  • 加密编码总结

    url编码 base64编码 工作中碰到url与base64配合加解密的问题,base64编码后的字符串中可能含有...

  • URL编码表 | Base64编码表

    URL编码表: Base64编码表:

网友评论

      本文标题:Base64编码

      本文链接:https://www.haomeiwen.com/subject/zxdfbxtx.html