How to decrypt DES using asp/c#/vb ?

  • Thread starter Thread starter Kelvin
  • Start date Start date
Hi Nick,

Do you have sample or tutorial how to decrypt 3DES/DES using traditional
asp or C#/ASPX ?
Please advise.
 
Hello Tai:

Encryption:

TripleDES des3 = new TripleDESCryptoServiceProvider();
byte[] buff = ASCIIEncoding.ASCII.GetBytes(source.Text);
byte[] bytesKey = ASCIIEncoding.ASCII.GetBytes(encKey.Text);
des3.Mode = CipherMode.ECB;
if (encKey.Text.Length != 24)
{
outputStr = "Key size is illegal. Please supply a 192bit key (24
characters)";
}
else
{
des3.Key = bytesKey;
byte[] encrypted = des3.CreateEncryptor().TransformFinalBlock(buff, 0,
buff.Length);
outputStr = Convert.ToBase64String(encrypted);
}

Decryption:


TripleDES des3_dec = new TripleDESCryptoServiceProvider();
byte[] buff = ASCIIEncoding.ASCII.GetBytes(source.Text);
byte[] bytesKey = ASCIIEncoding.ASCII.GetBytes(encKey.Text); // Note that
the key is 192bit long
des3_dec.Mode = CipherMode.ECB;
.....
outputStr =
Convert.FromBase64String(des3_dec.CreateDecryptor().TransformFinalBlock(buff
, 0, buff.Length));

I gleaned this from a couple of other postings on the
microsoft.public.dotnet.security newsgroup.
I'm no expert on crypto, but some of the folks on that NG certainly are, and
may be able to help you further if this code isn't sufficient.

Hope this helps,
--- Nick
 
Hi Nick,

Thanks for your support first ! Do u have any sample to support
traditional asp code ?
Please advise !
 
Back
Top