Solved

Problem Generating 64 bit DES key

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

863 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

18 Experts available now in Live!

Get 1:1 Help Now