使加密字符串与输入字符串长度相同?

时间:2021-10-27 18:23:57

I have a 15 digit string to encrypt.

我有一个15位数的字符串要加密。

I have tried using .NET's various encryption functions but all my encrypted strings are at least 24, 28 or 32 in length.

我尝试过使用.NET的各种加密函数,但我所有的加密字符串长度至少为24,28或32。

I have heard of CipherMode.CTS with Padding = None that produces the same length output as the input length but I can't seem to get the same result. I have toyed with the block-size, key-size and salt size.

我听说CipherMode.CTS有Padding = None,它产生与输入长度相同的长度输出,但我似乎无法得到相同的结果。我玩弄了块大小,大小和盐的大小。

I don't mind adding a digit to my input string to make it 16 in length.

我不介意在我的输入字符串中添加一个数字,使其长度为16。

Anyone know a workaround?

有人知道解决方法吗?

2 个解决方案

#1


3  

If you use ECB mode, it'll round the input up to the next multiple of the block size, and then produce exactly that same size of output.

如果使用ECB模式,它会将输入四舍五入到块大小的下一个倍数,然后生成完全相同的输出大小。

Almost every other mode includes/uses an Initialization Vector (IV) that makes the output one block larger than the input (again, after the input has been rounded up to the next multiple of the block size).

几乎所有其他模式都包括/使用初始化向量(IV),使输出比输入大一个块(再次,在输入被舍入到块大小的下一个倍数之后)。

Most stream ciphers produce output that is exactly the same size as the input -- but in typical encryption libraries, stream ciphers are much less common than block ciphers. One reason is that key distribution is a much more serious problem with stream ciphers (using the same key twice with a stream cipher produces a major security hole).

大多数流密码产生的输出与输入的大小完全相同 - 但在典型的加密库中,流密码远不如分组密码。一个原因是密钥分发对于流密码来说是一个更严重的问题(使用相同的密钥两次使用流密码会产生一个主要的安全漏洞)。

#2


2  

The code word is Format-preserving encryption. Unfortunately I am not aware of any .NET implementations (the framework certainly hasn't any).

代码字是格式保留加密。不幸的是我不知道任何.NET实现(框架肯定没有)。

#1


3  

If you use ECB mode, it'll round the input up to the next multiple of the block size, and then produce exactly that same size of output.

如果使用ECB模式,它会将输入四舍五入到块大小的下一个倍数,然后生成完全相同的输出大小。

Almost every other mode includes/uses an Initialization Vector (IV) that makes the output one block larger than the input (again, after the input has been rounded up to the next multiple of the block size).

几乎所有其他模式都包括/使用初始化向量(IV),使输出比输入大一个块(再次,在输入被舍入到块大小的下一个倍数之后)。

Most stream ciphers produce output that is exactly the same size as the input -- but in typical encryption libraries, stream ciphers are much less common than block ciphers. One reason is that key distribution is a much more serious problem with stream ciphers (using the same key twice with a stream cipher produces a major security hole).

大多数流密码产生的输出与输入的大小完全相同 - 但在典型的加密库中,流密码远不如分组密码。一个原因是密钥分发对于流密码来说是一个更严重的问题(使用相同的密钥两次使用流密码会产生一个主要的安全漏洞)。

#2


2  

The code word is Format-preserving encryption. Unfortunately I am not aware of any .NET implementations (the framework certainly hasn't any).

代码字是格式保留加密。不幸的是我不知道任何.NET实现(框架肯定没有)。