-1

I am in need of some explanations on the corresponding line, which I do not understand:

KeyGenerationParameters kgp = new KeyGenerationParameters(sr,(DESParameters.DES_KEY_LENGTH) * 8);

Would it stop working, if I had, for instance, the number 6 instead of 8?

Unheilig
  • 16,196
  • 193
  • 68
  • 98
qwerty
  • 486
  • 1
  • 11
  • 37
  • Have you read javadoc for classes your mention? http://bouncycastle.org/docs/docs1.5on/org/bouncycastle/crypto/KeyGenerationParameters.html uses bits as length units. – Oleg Estekhin Apr 12 '15 at 08:52
  • 1
    "*Would it stop working if...*": Why don't you try this operation? – mins Apr 12 '15 at 09:27
  • Maybe because the constant is defined in terms of bytes, and the `KeyGenerationParameters` class wants it in terms of *bits* – Ian McLaird Apr 13 '15 at 02:37

2 Answers2

0

It is multiplied by 8 because it is in bytes otherwise. The code wants bits.

Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
AlwaysQuestioning
  • 1,464
  • 4
  • 24
  • 48
0

strength - the size, in bits, of the keys we want to produce.

it is from javadoc for KeyGenerationParameters. The DESPArameters.DES_KEY_LENGTH stores value 8 (DES key length in bytes), but KeyGenerationParameters requires key length in bits. 8 bytes * 8 = 64 bits in a case of KeyGenerationParameters. You can just put the constant value 64.

This class can be used for random key generation for any algorythm, for example, to generate DES key you must use value of 64, to generate 3DES key 128 or 192.

Juris Lacis
  • 132
  • 3