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?
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL