开发者

How to encrypt the data without exceed size of original data?

My question is simple I am expecting encryption algorithm,

I need to encrypt a original data(text et开发者_开发技巧c.) that encrypted data size should be same size of original data size? Share your idea kindly?

Example: Original data is "test" (so length of text is 4) the expected encrypted data should be like this "etst" (so length is 4).


This is not always possible, especially with short amounts of data. I am pretty sure that all the standard algorithms work on "blocks", which are usually the length of the key. So unless you go with a really weak key, or use something weak like substitution cipher or caesar cipher your encrypted data could end up a little longer than the original.

Actually, according to this page you can use a stream cipher and get encrypted text that is the same size as the input. The example given is RC4.


Unless you are using a plain substitution cypher, (replacing a letter with a different letter or symbol), you are looking at having a file that increases in size. If you go with a substitution cypher those are extremely easy to break. Why do you NEED to keep the file the same size?


Most encryption algorithms work on blocks of data. AES, for example, works on blocks of 128bit or 16 bytes. If you overflow a block by even 1 byte, AES must require another block worth of data.

with AES, you will always have a result that is a multiple of 16bytes.

If you resulting data is much larger, you should make sure you're feeding in a byte stream. If you, for some reason, copy in a file as text, .Net will convert it to Unicode which will change your data from 8bits per char to 16bit per char which will double the size of the output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜