Solved

Problem Generating 64 bit DES key

Posted on 2001-07-19
2
1,532 Views
Last Modified: 2010-08-05
I am using java's cryptography packages and using SunJCE as the security provider.  I am trying to create a 64 bit DES key.  I am getting the following error:

java.security.InvalidParameterException: Wrong keysize: must be equal to 56

Here is the code I am using:

Provider sunJCE = new com.sun.crypto.provider.SunJCE();
Security.addProvider(sunJCE);

KeyGenerator generator = KeyGenerator.getInstance("DES");

generator.init(64, new SecureRandom());
Key key = generator.generateKey();
System.out.println("Generating DES Key... done");

ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(args[0]));
out.writeObject(key);
out.close();

System.out.println("DES Key is saved to file" + args[0]);

When I changed 64 to 56, the key was generated correctly but I need a 64 bit key.  Any ideas?  Thanks.
0
Comment
Question by:paulca
2 Comments
 

Expert Comment

by:berserks
ID: 6300035

I think if you remove the 64 and just have
generator.init(new SecureRandom())
you don't have to specify the key size.  I did the following and it worked fine:


KeyGenerator keyGenerator = KeyGenerator.getInstance("DES");
      keyGenerator.init(new SecureRandom());
      SecretKey ourSecretKey = keyGenerator.generateKey();
      SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
      Class spec = Class.forName("javax.crypto.spec.DESKeySpec");
      DESKeySpec ks = (DESKeySpec)skf.getKeySpec(ourSecretKey,spec);
      // set ksBytes
      setKsBytes(ks.getKey());

      // encrypt a dummy string in order to generate an init vector
      Cipher newCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
      newCipher.init(Cipher.ENCRYPT_MODE, ourSecretKey);
      newCipher.doFinal("plaintext".getBytes());
      // get initialization vector
      byte[] initVector = newCipher.getIV();
      setIV(initVector);
0
 
LVL 2

Accepted Solution

by:
barrel earned 100 total points
ID: 6301310
A 56 bit DES key is in fact a 64 bit key, the 8 bits "missing" are filled with Dummy values.

The reason for needing 64 bits for the encryption algorithm is obvious, the reason why only 56 can be entered is because of the Wassenaar Arrangement which lists encryption as militairy property/technology (or something like that). Any (well.. not any) symmetric encryption algorithm may only use 56 bits keys.

For more information:

http://www.rsa.com/rsalabs/faq/6-5-3.html
http://www.luc.co.nz/political.html
http://www.epic.org/crypto/export_controls/regs_1_00.html

The encryption algortihm will thus fill the 56 bits with 8 dummy bits, giving 8 blocks of 8 bits. This is your 64 bits encryption

Hope this helps
Barrel
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 47
How  can  i  resolve  HTTP Status 404 -? 8 58
maven disable workspace resolution 1 37
ejb entity bean example 2 31
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question