跨平台base64数据传输注意问题

今天用base64编码传输json串,android端那边始终看不到图片!

首先发现android端接收的json串长度不一致,仔细研究发现android端接收到的json数据里把服务器数据里的"/"和"+"过滤掉了。

查看资料发现,之前使用:new BASE64Encoder().encode(bytes)来转byte[]。

跨平台传输base64编码数据需使用:Base64.encodeBase64URLSafeString(bytes)(方法含义:将二进制数据编码使用URL安全变化的Base64算法但不块输出)。

Modifier and Type Method and Description
static byte[] decodeBase64(byte[] base64Data)

Decodes Base64 data into octets

static byte[] decodeBase64(String base64String)

Decodes a Base64 String into octets

static BigInteger decodeInteger(byte[] pArray)

Decodes a byte64-encoded integer according to crypto standards such as W3C‘s XML-Signature

static byte[] encodeBase64(byte[] binaryData)

Encodes binary data using the base64 algorithm but does not chunk the output.

static byte[] encodeBase64(byte[] binaryData, boolean isChunked)

Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.

static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe)

Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.

static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize)

Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.

static byte[] encodeBase64Chunked(byte[] binaryData)

Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks

static String encodeBase64String(byte[] binaryData)

Encodes binary data using the base64 algorithm but does not chunk the output.

static byte[] encodeBase64URLSafe(byte[] binaryData)

Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.

static String encodeBase64URLSafeString(byte[] binaryData)

Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.

static byte[] encodeInteger(BigInteger bigInt)

Encodes to a byte64-encoded integer according to crypto standards such as W3C‘s XML-Signature

static boolean isArrayByteBase64(byte[] arrayOctet)

Deprecated.

1.5 Use isBase64(byte[]), will be removed in 2.0.

static boolean isBase64(byte octet)

Returns whether or not the octet is in the base 64 alphabet.

static boolean isBase64(byte[] arrayOctet)

Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.

static boolean isBase64(String base64)

Tests a given String to see if it contains only valid characters within the Base64 alphabet.

protected boolean isInAlphabet(byte octet)

Returns whether or not the octet is in the Base64 alphabet.

boolean isUrlSafe()

Returns our current encode mode.

时间: 2024-08-26 01:05:59

跨平台base64数据传输注意问题的相关文章

xml文件解析基础和签名

0. 前言 参考文档1:使用dom4j读取xml文件的四种方式 参考文档2:dom4j解析xml文件 参考文档3:String 和 document 的相互转换总结 参考文档4: Java SE 6中 XML 数字签名的标准 Java 接口 参考文档5:XML Security with Digital Signature in JAVA 1.xml文件的解析 1.1 基本的jdk解析xml的原始api解析 声明 1.以下代码块要放到一个类中才能运行 dom类型为:org.w3c.dom.* 解

pickle\json,configparser,hashlib模块

python常用模块 目录 python常用模块 json模块\pickle模块 configparser模块 hashlib模块 subprocess模块 json模块\pickle模块 首先说一下序列化和反序列化 . 序列化:将数据内容转化成一种特定的格式. 反序列化:将特定的格式在转化成数据内容. 其实我们之前学过序列化和反序列化的方法,即将内存中的数据转化为字符串的格式存进文件中,在从文件中利用eval()的方法反序列化出来.这也是一种方法,但是现在有更方便的方法. json模块是个序列

openssl与数据传输安全

数据安全服务的几个方面:     1.认证             访问控制 阻止对资源的未授权访问     2.数据保密性      3.数据完整性          要保证发送方所发送的数据没有被修改...     4.不可否认性 一.怎么验证数据的完整性.也就怎么知道数据在传输的过程中没有被修改过.这就要使用到单向加密算法,提取数据的指纹(特征码). 数据的传输双方为:甲.乙 甲:在数据传输之前,提取该数据的"指纹"然后,把数据指纹附加在数据中一起发送给乙. 乙:接收到该数据以后

跨平台网络通信与server编程框架库(acl库)介绍

一.描写叙述 acl project是一个跨平台(支持LINUX,WIN32,Solaris,MacOS,FreeBSD)的网络通信库及server编程框架,同一时候提供很多其它的有用功能库.通过该库,用户能够很easy地编写支持多种模式(多线程.多进程.非堵塞.触发器.UDP方式)的server程序,WEB 应用程序,数据库应用程序.此外,该库还提供了常见应用的client通信库(如:HTTP.SMTP.ICMP.memcache.beanstalk),常见流式编解码库:XML/JSON/MI

java进阶12 Base64 UrlBase64 Hex 加密 解密技术

java的加密与解密技术: 现在的加密技术主要有 单向加密算法:以MD5 SHA算法为代表 对称加密算法:以DES 三重DES AES PBE算法为代表 非对称加密算法:以RSA为代表 简要的说下这三种加密算法的区别 先是单向加密算法,顾名思义,它不会有密钥,因为它是单向的,加密之后无法解密,就连程序猿都无法知道加密之后的东西是什么 主要用处是数据完整性的验证. 对称加密算法,其特征是公钥与私钥相同.一般用来数据储存,比如将数据加密之后存入数据库,那么数据库管理员就无法泄密数据库中的类容 有密钥

跨平台的.NET邮件协议MailKit组件解析

发起的.NET Core开源组织号召,进展的速度是我自己也没有想到的,很多园友都积极参与(虽然有些人诚心砸场子,要是以我以前的宝脾气,这会应该被我打住院了吧,不过幸好是少数,做一件事总有人说好,也有人说是用武汉话说"闹眼子"),.NET社区不是没有乐于共享知识的人,只是没有一个完整和良好的生态环境,总之希望国内的.NET发展越来越强大.我在这里想到一句话"我们希望自己可以做巨浪,但我们也甘愿做巨浪来袭前的小浪". 上面扯淡完毕(我这人干正事前,都要将一些扯淡的话,这

DES非对称加密解密跨平台(C#,安卓,ios)

#region 跨平台加解密(c# 安卓 IOS) public static string sKey = "123456"; /// <summary> /// 解密 /// </summary> /// <param name="pToDecrypt">要解密的以Base64</param> /// <param name="sKey">密钥,且必须为8位</param>

acl 是一个跨平台的网络通信库及服务器编程框架

acl 工程是一个跨平台(支持LINUX,WIN32,Solaris,MacOS,FreeBSD)的网络通信库及服务器编程框架,同时提供更多的实用功能库.通过该库,用户可以非常容易地编写支持多种模式(多线程.多进程.非阻塞.触发器.UDP方式.协程方式)的服务器程序,WEB 应用程序,数据库应用程序.此外,该库还提供了常见应用的客户端通信库(如:HTTP.SMTP.ICMP.redis.memcache.beanstalk.handler socket),常见流式编解码库:XML/JSON/MI

cryptopp开源库的使用(二):base64加密

很多时候我只是优秀工具的使用者,优秀的工具用好了才能发挥作用 最近使用cryptopp的base64对压缩后的zip文件内容进行加密遇到了问题. 首先zip压缩没问题,可是最后得到的base64字符串不对: 1.长度不对(问题应该是源字符串的问题) 2.使用现成的工具解密得不到zip文件内容(问题没有头绪) 既然没法从问题的表现来推理解决,那就从正常逻辑往后判断问题的根源点 1.先检查zip的读取,利用fread读出后再fwrite写入,以确定fread的内容是有效的 此过程中发现fwrite写