0

the below code gives me string like this "3TA3cATum2VMStTsnJ6DPz5Xx5JH2SoZDdevsd2WJrYapJQjcTOOQ==" but what I want is to encrypt mystring(strr) in a shorter form (need to convert something like tiny URL)

private byte[] key={};
private byte[] IV={18,52,86,120,144,171,205,239};
public string prvtkey="!#$a54?3";
string strr="placeesOFPrj/modulesNamee/mypagesss/ds2.aspx";
key = System.Text.Encoding.UTF8.GetBytes(prvtkey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(strr);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
txt.Text=Convert.ToBase64String(ms.ToArray());
Artjom B.
  • 61,146
  • 24
  • 125
  • 222

1 Answers1

7

You need some kind of database to map some random short string to the long, because the encrypted version of something cannot be smaller than the input. It would be impossible to reverse it, so you need some help reversing it by creating a mapping.

If you don't want a random string then you can certainly use a hash of the long string and truncate it to the length you want it to have, but there is no way around a database or storage.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222