I have a 15 digit string to encrypt.
I have tried using .NET's various encryption functions but all my encrypted strings are at least 24, 28 or 32 in length.
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.
I don't mind adding a digit to my input string to make it 16 in length.
Anyone know a workaround?
The code word is Format-preserving encryption. Unfortunately I am not aware of any .NET implementations (the framework certainly hasn't any).
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.
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).
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With