Base64编码与Ascii85编码 [英] Base64 encoding vs Ascii85 encoding

查看:301
本文介绍了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 编码器>编解码器,将字节数组转换为字符串. 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 decode -> decrypt -> decompress -> deserialize using default Jackson deserializer.

Base64编码增加了输出的大小(序列化中的gzip步骤旨在帮助减轻这种增加),因此我检查了Google以查看是否有更有效的选择,这导致我

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比较常见.在大多数情况下,大小的差异实际上并不显着,并且,如果您在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编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆