Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Is there any way to encrypt the whole Input data into 16 to 24 character alphanumeric string and again able to decrypt it into normal string in c#?

What I have tried:

Is there any way to encrypt the whole Input data into 16 to 24 character alphanumeric string and again able to decrypt it into normal string in c#?
Posted
Updated 8-Feb-19 1:21am
v2
Comments
Richard MacCutchan 8-Feb-19 7:09am    
You already have the answer. Why have you updated this question?

No.

You can't encrypt data into a fixed size at all, and particularly not into a small number of bits: if you could, why would we stream movies as 10GB lumps, web pages as huge chunks of "text"? We'd just encrypt them to 24 char alpha values and send that instead. Why would we store files on HDD's in "raw input" instead of storing the 24 char value and expanding it when we needed it? Think of the cost savings!

Rather the opposite: encrypted data is very often significantly larger than the unencrypted source!

You are probably thinking of MD5 and SHA algorithms which do generate fixed length outputs - but those are not encryption algorithms, they are hashing algorithms, and the output cannot be converted back to restore the original input data (and that is by design).
 
Share this answer
 
Quote:
Is there any way to encrypt the whole Input data into 16 to 24 character alphanumeric string and again able to decrypt it into normal string in c#?

Yes, only if input is no more than 24 characters alphanumeric string.
Beware, with utf-8, some characters are encoded on more than an 8 bits char.
If your question imply changing the size of input to less than 24 chars, it is compression. And nothing can guaranty a given output size.

Basically, encryption does not change the size of input, or makes it bigger with bloc cypher, because input is expanded to multiple of bloc size.
 
Share this answer
 
Some remarks:
  • Encryption is not compression. If you are looking for way to reduce the size of your data, then you should search for compression algorithms.
  • Usually encryption algorithms (e.g. the AES you tagged your question with ) produce binary data. You may represent such binary output with ASCII characters by means of base64[^] if you wish (this would increase the output size).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900