美文网首页
Andorid自带的Base64编解码表

Andorid自带的Base64编解码表

作者: Singal11 | 来源:发表于2018-07-30 14:43 被阅读0次

在Android提供的android.util.Base64类中,提供了base64基本的几种编解码格式,源码如下

/**
* Default values for encoder/decoder flags.
*/
public static final int DEFAULT = 0;   // 此flag下编码完成的String中会包含换行符\n,+号,末尾以“=”结束

/**
* Encoder flag bit to omit the padding '=' characters at the end
* of the output (if any).
*/
public static final int NO_PADDING = 1;  //此flag下最终的编码字符串会包含换行符\n,但是末尾去掉了“=”

/**
* Encoder flag bit to omit all line terminators (i.e., the output
* will be on one long line).
*/
public static final int NO_WRAP = 2; // 此flag下最终编码字符串不包含换行符\n,+号,且字符串全在一行,设置此flag后CRLF flag无效

/**
* Encoder flag bit to indicate lines should be terminated with a
* CRLF pair instead of just an LF. Has no effect if {@code
* NO_WRAP} is specified as well.
*/
public static final int CRLF = 4;  // 编码后用CR LF这一对作为一行末尾的换行,而不是unix风格的LF换行

/**
* Encoder/decoder flag bit to indicate using the "URL and
* filename safe" variant of Base64 (see RFC 3548 section 4) where
* {@code -} and {@code _} are used in place of {@code +} and
* {@code /}.
*/
public static final int URL_SAFE = 8;  // 编码后,用-代替+,用_代替·/,避免请求是url编码造成的传输问题,包含换行符\n

/**
* Flag to pass to {@link Base64OutputStream} to indicate that it
* should not close the output stream it is wrapping when it
* itself is closed.
*/
public static final int NO_CLOSE = 16;

附上Base64的元码表【from wiki

image.png

小结

用flag Default编码后,字符串中带有+号和\n换行符,发起网络请求时,当以base64字符串作为参数值传递时,url为了传输安全会把+号全部变成空格,在接收端就会产生各种问题,且前端用的部分的Base64解码库不支持\n,当字符串中含有\n时无法解码还原为图片。所以Base64编码时建议使用NO_WRAP | URL_SAFE,这样可以避免较多问题。

相关文章

  • Andorid自带的Base64编解码表

    在Android提供的android.util.Base64类中,提供了base64基本的几种编解码格式,源码如下...

  • 编码

    TextEncoder, TextDecoder(实验中的功能) base64 编解码 Base64编码作用:由于...

  • C语言实现base64编解码

    base64编解码 工作中经常会用到base64编解码, 有些开源库中也有实现, 但是如果再去看他们的怎么用有时候...

  • base64

    Python内置的base64可以直接进行base64的编解码: 由于标准的Base64编码后可能出现字符+和/,...

  • iOS7 base64编解码

    文档 使用 参考 使用Base64编解码NSData和NSString对象

  • 批处理下的Base64编解码

    文件版 命令:certutil /?,参考 批处理版Base64编码工具 BASE64编解码工具bse.exe 字...

  • Base64编码简单总结

    1 Base64编码原理 随着iOS7正式版推出,Apple增加了使用Base64编解码的支持。Base64编码之...

  • Android-加密机制详解

    编解码 Base64编码算法 Base64编码算法是一种用64个字符(ABCDEFGHIJKLMNOPQRSTUV...

  • base64图片和字符串编解码详细过程

    base64图片和字符串编解码详细过程 base64图片编码过程 1、读取图片路径 NSString *path...

  • 在线工具

    在线编码工具:• BASE64编解码工具:https://base64.supfree.net/[https://...

网友评论

      本文标题:Andorid自带的Base64编解码表

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