Solved

Problem Generating 64 bit DES key

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

696 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