1
$\begingroup$

If the data is not a multiple of 64 bits, then I can use padding. I know that it is not secure. But if the key is less than or more than 64 bits, should I ask the user to enter the key again, or should I pad / truncate it?

$\endgroup$
2
  • $\begingroup$ DES is not secure, so there's no secure choice here... $\endgroup$ – otus Aug 24 '15 at 14:36
  • $\begingroup$ Thanks @otus. I am writing a program for my lab purpose. I am using it for any industry data security. That's why I have posted this question $\endgroup$ – Gibbs Aug 24 '15 at 14:47
1
$\begingroup$

A DES key is, by definition, a (pseudo)randomly chosen sequence of 8 × 7 = 56 key bits, plus 8 parity bits,* for a total of 64 bits. If what you have isn't 64 bits long (with the appropriate parity bits), then it's not a DES key, but something else (e.g. a passphrase).

To turn that "something else" into a DES key, you need a key derivation function (KDF). There are several standard and commonly used ones, most of them based on cryptographic hash functions.

If the "something else" you have might contain less than 56 bits of entropy (which is likely, if it's e.g. a user-chosen password), then you will most likely want a key stretching KDF such as PBKDF2. Such KDFs are deliberately slow (and their slowness is adjustable) to make brute force guessing attacks harder.

Also, please note that the 56-bit key size of plain DES is itself too short to resist brute force attacks using modern hardware, making DES insecure. If you can't use a more modern cipher like AES, you should at least use Triple DES, which doubles the effective key size of DES to 112 bits (at the cost of also tripling the work needed for encryption).

(Ps. Of course, the "something else" could also be a corrupted DES key. In that case, you should just reject it, and report the error to the user who supplied the key.)

*) The standard way of storing a DES key is as a sequence of eight bytes, each consisting of 7 key bits and one redundant parity bit. Thus, the standard form of the key has 64 bits, even though only 56 of them are actually used for cryptographic purposes. This is a peculiarity of DES, not shared by most later block ciphers.

$\endgroup$
2
  • $\begingroup$ Actually, it's not historic; instead, a DES key is defined to be 64 bits. Yes, 8 of those bits do not actually contribute for the transform (and so are typically ignored for cryptographical purposes), but as far as the API is concerned, all 64 bits need to be there. $\endgroup$ – poncho Aug 24 '15 at 21:39
  • $\begingroup$ @poncho: Fair enough. Corrected. $\endgroup$ – Ilmari Karonen Aug 24 '15 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.