Base64 encoding vs Ascii85 encoding(Base64 编码与 Ascii85 编码)
问题描述
我的工作项目是使用 Jackson JSON 序列化程序将一堆 Java 对象转换为字符串,以便将它们发送到 REST 服务.
My project at work is using the Jackson JSON serializer to convert a bunch of Java objects into Strings in order to send them to REST services.
其中一些对象包含敏感数据,所以我编写了自定义序列化程序来将这些对象序列化为 JSON 字符串,然后 gzip 它们,然后使用 AES
加密它们;
Some of these objects contain sensitive data, so I've written custom serializers to serialize these objects to JSON strings, then gzip them, then encrypt them using AES
;
这会将字符串转换为字节数组,因此我在 中使用 Base64 编码器Apache commons
编解码器将字节数组转换为字符串.REST 接口背后的自定义反序列化器反转了这个过程:
This turns the strings into byte arrays, so I use the Base64 encoder in Apache commons
codec to convert the byte arrays into strings. The custom deserializers behind the REST interfaces reverse this process:
base64 解码 ->解密->解压->使用默认的 Jackson 反序列化器进行反序列化.
Base64
编码会增加输出的大小(序列化中的 gzip 步骤旨在帮助改善这种增加),所以我检查了谷歌,看看是否有更有效的替代方案,这导致我this 之前提出 Ascii85 编码作为更有效的替代方案 -
Base64
encoding increases the size of the output (the gzip step in serialization is meant to help ameliorate this increase), so I checked Google to see if there was a more efficient alternative, which led me to this previous stackoverflow thread that brought up Ascii85 encoding as a more efficient alternative -
Base64
将输出大小增加 33%,Ascii85
将输出大小增加 25%.
Base64
adds 33% to the size of the output, Ascii85
adds 25% to the size of the output.
我发现了一些 Java Ascii85 实现,例如Apache pdfbox,但我对使用编码有点怀疑——似乎几乎没有人在使用或实现它,这可能只是意味着 Base64 有更多的惯性,或者这可能意味着 Ascii85 存在一些不稳定的问题.
I found a few Java Ascii85 implementations e.g. Apache pdfbox, but I'm a bit leery to use the encoding - it seems like hardly anybody is using or implementing it, which might just mean that Base64 has more inertia, or which may instead mean that there's some wonky problem with Ascii85.
有人知道更多关于这个主题的信息吗?Ascii85 是否有任何问题意味着我应该改用 Base64?
Does anybody know more on this subject? Are there any problems with Ascii85 that mean that I should use Base64 instead?
推荐答案
Base64 是 way 更常见.在大多数情况下,大小的差异实际上并不显着,如果您在 HTTP 级别(将压缩 base64)而不是在您的有效负载中添加 ,您很可能会发现差异完全消失了.
Base64 is way more common. The difference in size really isn't that significant in most cases, and if you add at the HTTP level (which will compress the base64) instead of within your payload, you may well find the difference goes away entirely.
Ascii85 是否有任何问题意味着我应该改用 Base64?
Are there any problems with Ascii85 that mean that I should use Base64 instead?
我强烈建议使用 base64,因为它所以更广泛.这几乎是将二进制数据表示为文本的规范方式(当然,除非您想使用十六进制).
I would strongly advise using base64 just because it's so much more widespread. It's pretty much the canonical way of representing binary data as text (unless you want to use hex, of course).
这篇关于Base64 编码与 Ascii85 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Base64 编码与 Ascii85 编码
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01