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

T

Tai Kelvin

Hi Nick,

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

Nick Malik

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
 
T

Tai Kelvin

Hi Nick,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top