tags:

views:

111

answers:

2

Hi there, I have to encrypt a text by using the DES algorythm with a hash created in MD5. The MD5 function has the parameters: salt (byte[8]) and key (string 6), It has to iterate 1000 times. When I pass the MD5 encryption function it returns me a byte[16].

The DES function parameters are: the string to encrypt and the key (returned by the MD5 function). But when I try to assign the key value to the key encoder I get an exception because it waits a bte[8] instead of a byte[16]. I've tryed to get the first 8 bytes or the last 8 bytes..... But it doesn't work (I have an example and I have to get the same result).

Some ideas???

A: 

Why are you using the hash as an encryption key? Keys should be cryptographically secure random data, something a hash is not. Hashing itself is not encryption at all.

DES keys are 56 bits normally packaged in 8 bytes, so taking the first 8 bytes from the hash means you have a key that is too long (depending on if it's signed or unsigned), you need to extract 56 bits if you must use the hash as a source.

blowdart
It seems that Paloma is doing key stretching (http://en.wikipedia.org/wiki/Key_strengthening) of a user-supplied key by 1000 iterations of MD5. It's a valid technique.
atzz
Well he'd be better off deriving a key using something like PKCS #5
blowdart
+1  A: 

DES (not to be confused with 3DES) has 56 bit keys. Your problem will require more definition in order to determine the correct choice for the key.

There is no reason to use DES today. There are far better, unbroken, algorithms available.

Yann Ramin