简体   繁体   English

使用AES限制加密结果

[英]Limit the encrypted result using AES

I need to encrypt a text (16 chars), preferably using AES, and I need limit the length of the result encrypted text (14 or 16 characteres). 我需要加密文本(16个字符),最好使用AES,并且我需要限制结果加密文本的长度(14个或16个字符)。 The encrypted has to be only chars and numbers (not '=', '?', ...) Is it possible? 加密的只能是字符和数字(不是'=','?',...)是可能的吗?

I'll need to get back the original text from the cipher text(encrypted). 我需要从密文(加密的)中取回原始文本。

Is there a way to do this using RijndaelManaged (System.Security.Cryptography )? 有没有一种方法可以使用RijndaelManaged(System.Security.Cryptography)?

The cypher-text needs to be at least as long(in an entropic sense) as plain-text. 密文需要至少与纯文本一样长(在熵的意义上)。 You can't losslessly compress arbitrary texts. 您不能无损地压缩任意文本。 So if you limit your output to log2(10+2*26)*16=95 bits the input can't have any more entropy than that. 因此,如果将输出限制为log2(10 + 2 * 26)* 16 = 95位,则输入的熵将不止于此。 This has nothing to do with AES, it's a mathematical limitation that applies to all lossless encodings. 这与AES无关,这是一种数学限制,适用于所有无损编码。

What's a character? 什么角色 A byte a char or a unicode-codepoint? 一个bytechar或unicode-codepoint?

AES has the additional problem that it's a block cypher, the minimum output size is equal to the blocksize, 128bits. AES还有一个问题,它是一个块密码,最小输出大小等于128块大小。 And since the output appears random it can't be compressed after encrypting. 而且由于输出看起来是随机的,因此加密后无法对其进行压缩。 And that already exceeds your limit. 那已经超出了您的限制。 And most encryption modes add a bit of additional padding. 而且大多数加密模式都增加了一些额外的填充。

There are functions which map arbitrary length input to constant length output. 有一些函数可以将任意长度的输入映射到恒定长度的输出。 They are called hash-functions. 它们称为哈希函数。 But following the pidgeon-hole-principle they map multiple inputs to an output. 但是遵循pidgeon-hole原理,它们将多个输入映射到一个输出。 So you can't get back the input for all possible inputs. 因此,您无法取回所有可能输入的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM