AES输出,是否比输入小? [英] AES output, is it smaller than input?

查看:187
本文介绍了AES输出,是否比输入小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加密一个字符串并将其嵌入到一个URL中,所以我想确保加密输出不大于输入。

I want to encrypt a string and embed it in a URL, so I want to make sure the encrypted output isn't bigger than the input.

是AES要去的方式?

推荐答案

不可能创建任何一个总是会创建比输入更小的输出的算法,但可以反转任何输出回输入。如果你允许不大于输入,那么基本上你只是说同态算法,它们的总体尺寸与输入的大小一样。这是由于鸽子原则

It's impossible to create any algorithm which will always create a smaller output than the input, but can reverse any output back to the input. If you allow "no bigger than the input" then basically you're just talking isomorphic algorithms where they're always the same size as the input. This is due to the pigeonhole principle.

加上加密通常有一点填充(例如,到最接近8个字节,向上舍入 - 在AES中,这是<16> 字节)。哦,最重要的是你会遇到文本和二进制之间转换的问题。加密算法通常以二进制方式工作,但URL是文本。即使你假设ASCII,你最终可能会得到不是ASCII的加密二进制值。在文本中表示任意二进制数据的最简单方法是使用base64。还有其他替代方案是非常fiddly,但通用的将文本转换为二进制,加密,将二进制转换为文本模式是最简单的。

Added to that, encryption usually has a little bit of padding (e.g. "to the nearest 8 bytes, rounded up" - in AES, that's 16 bytes). Oh, and on top of that you're got the issue of converting between text and binary. Encryption algorithms usually work in binary, but URLs are in text. Even if you assume ASCII, you could end up with an encrypted binary value which isn't ASCII. The simplest way of representing arbitrary binary data in text is to use base64. There are other alternatives which would be highly fiddly, but the general "convert text to binary, encrypt, convert binary to text" pattern is the simplest one.

这篇关于AES输出,是否比输入小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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