Solved

Problem Generating 64 bit DES key

Posted on 2001-07-19
2
1,475 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now