Re: Security and DES keys
Shoot me. 8 bytes = 56 bits. Argh!
Jason
"Jason Bock" <jrbock@execpc.com> wrote in message
news:38cd59d6$1@news.devx.com...
> I'm trying to generate a DES key, but the key length I get back is 8 and I
> thought it should be 56. Here's my code:
>
> import java.io.*;
> import java.util.*;
> import java.security.*;
> import javax.crypto.*;
> import javax.crypto.spec.*;
>
> // assume pwd is equal to something like "javapassword"
> MessageDigest messagedigest = MessageDigest.getInstance("SHA");
> System.out.println("MessageDigest algorithm made via SHA algorithm...");
> messagedigest.update(pwd.getBytes());
> String msgDigest = new String(messagedigest.digest());
> System.out.println("Message digest complete, length is " + (new
> Integer(msgDigest.getBytes().length)) );
>
> DESKeySpec dks = new DESKeySpec(msgDigest.getBytes());
> System.out.println("DESKeySpec complete...");
> SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
> System.out.println("SecretKeyFactory complete...");
> SecretKey key = skf.generateSecret(dks);
> System.out.println("Key generation is complete, length is " + (new
> Integer(key.getEncoded().length)) );
>
> What happens is that the SHA hash works (I have to duplicate this in
Windows
> via the CryptoAPI and I've verified that the two hash values are equal).
> However, the key length always ends up being 8, when the documentation
> states that key lengths should be 56. What ends up happening is that the
> first 8 bytes match between my Windows and Java code, but after that
nothing
> matches.
>
> How do I remedy this in my Java code?
>
> Thanks,
>
> Jason Bock
>
>
Re: Security and DES keys
Jason Bock <jrbock@execpc.com> wrote in message
news:38cd5e00@news.devx.com...
> Shoot me. 8 bytes = 56 bits. Argh!
>
> Jason
Shoot me again! I meant that the 8 bytes in the key = 64 bits, but the key
is the 56 bit key.