From Wikipedia :
The key supposedly consists of 64 bits; however, only 56 of them are actually used by the algorithm. Eight bits are used solely for parity and then discarded. Therefore, the effective key length is 56 bits, and it is never quoted as such. Every 8th bit of the selected key is discarded, that is, positions 8, 16, 24, 32, 40, 48, 56, 64 are deleted from the 64-bit key, leaving only the 56-bit key.
Thus, the least significant bits (that is, the 0th bit) are not used to construct keys; they can be used for parity on DESKeySpec.isParityAdjusted() .
EDIT: A simple test showing that the least significant bits are ignored:
SecretKeyFactory sf = SecretKeyFactory.getInstance("DES"); byte[] in = "test".getBytes("UTF-8"); Cipher c1 = Cipher.getInstance("DES"); c1.init(Cipher.ENCRYPT_MODE, sf.generateSecret(new DESKeySpec( new byte[] {0x10,0x20,0x30,0x40,0x50,0x60,0x70,(byte) 0x80}))); byte[] r1 = c1.doFinal(in); Cipher c2 = Cipher.getInstance("DES"); c2.init(Cipher.ENCRYPT_MODE, sf.generateSecret(new DESKeySpec( new byte[] {0x11,0x21,0x31,0x41,0x51,0x61,0x71,(byte) 0x81}))); byte[] r2 = c2.doFinal(in); assertArrayEquals(r1, r2);
axtavt
source share