Solved

Problem Generating 64 bit DES key

Posted on 2001-07-19
2
1,542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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:
Suggested Courses

734 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