Search code examples
asp.netencryptionencryption-symmetric

How to resolve error while implementing DES encrypt/decrypt in asp.net?


I am trying to implement DES encryption in asp.net application from the given link:

DES encrypt/decrypt

as per given code its working fine but if i add one more character in bytes variable its throwing exception

static byte[] bytes = ASCIIEncoding.ASCII.GetBytes("ZeroCool"); //Working fine
static byte[] bytes = ASCIIEncoding.ASCII.GetBytes("ZeroCoola"); //throwing exception

enter image description here

Anybody have idea how to resolve this one?

Is there any limit of 8 character in DES encryption?

Thanks


Solution

  • DES supports 56-bit keys, so you can't add another one. Actually 56 bits = 7 bytes, so I supposed "Zerocool" worked because all the characters are standard ASCII, and those only take 7 bits each.

    That being said...

    1. DES is a really old cipher. A 56-bit key can be easily bruteforced by a modern home computer. You should be using ciphers that support larger keys, like AES.

    2. I read this at the end of the article:

    Using DES, you can encrypt or decrypt users' passwords or something else, and you can delve into the algorithm if you like.

    Which has got me concerned. Passwords should never be encrypted. On the basis of that statement alone, I would disregard the entire article as useless.