Simple short Encrypt string to fixed length n matter what the input string length is

I would like to encrypt a string and it has to be decrypted back. The input string could be of varying length but the encrypted string must be a max of 15 characters and alphanumeric. This is for an intranet application, so security is not of a big concern. I should be able to decrypt it back to match in another page. I am using vs2012, c#, asp.net. Please advice. I tried rijndael, but it gives a long string. The encrypted string must be user friendly since the user will need to remember and enter it.

Thanks, DotNet

Jon Skeet
people
quotationmark

The input string could be of varying length but the encrypted string must be a max of 15 characters and alphanumeric.

This is clearly impossible. If you solved this, you would solve all possible storage concerns - after all, you'd be able to store the whole internet (viewed as one long string) in 15 alphanumeric characters (after decryption).

You haven't told us what the input string might consist of, either - assuming that by "alphanumeric" you mean A-Z, a-z, 0-9 that's only 62 possible characters. So there are 6215 possible encrypted strings. If your input is in UTF-16 code units, then just 6 code units has more possibilities (655366 is greater than 6215).

Basically, you're onto a losing proposition here - you should rethink your design.

Perhaps you should store the original value in a server, return some token, and then be able to fetch the value when you want? That isn't encryption, but it may satisfy your real requirements.

Further reading: the pigeonhole principle

people

See more on this question at Stackoverflow