Security and DES keys
I'm trying to generate a DES key, but the key length I get back is 8 and I
thought it should be 56. Here's my code:
// assume pwd is equal to something like "javapassword"
MessageDigest messagedigest = MessageDigest.getInstance("SHA");
System.out.println("MessageDigest algorithm made via SHA algorithm...");
String msgDigest = new String(messagedigest.digest());
System.out.println("Message digest complete, length is " + (new
DESKeySpec dks = new DESKeySpec(msgDigest.getBytes());
SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
SecretKey key = skf.generateSecret(dks);
System.out.println("Key generation is complete, length is " + (new
What happens is that the SHA hash works (I have to duplicate this in Windows
via the CryptoAPI and I've verified that the two hash values are equal).
However, the key length always ends up being 8, when the documentation
states that key lengths should be 56. What ends up happening is that the
first 8 bytes match between my Windows and Java code, but after that nothing
How do I remedy this in my Java code?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center