Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have found a Java implementation of AES CBC mode that runs in Netbeans. The lines below appear to create the key from password and salt:

SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 65536, 128);
SecretKey tmp = factory.generateSecret(spec);
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");

The key produced looks strange, here's an example:

secret key : javax.crypto.spec.SecretKeySpec@fffe8a18

I would expect 128 bit key like fffe8a1829ac45ed If I enter such key of my own making the program crashes.

I would appreciate an idiot's guide as to what is going on.

share|improve this question

closed as off-topic by Maeher, DrLecter, archie, CodesInChaos, figlesquidge Apr 15 '14 at 10:46

  • This question does not appear to be about cryptography within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

This question appears to be off-topic because it is about the inner workings of a particular java library. But to answer your question: What you are seeing is the Object ID being printed because you tried to print an object to the standard output. Check the documentation… what you are looking for is probably the output of the getEncoded() method. – Maeher Apr 15 '14 at 9:08
Your example "128 bit key" has only 64 bits once you convert it from hex to bytes. – CodesInChaos Apr 15 '14 at 9:32

SecretKeyFactory is a class from the javax.crypto library. This class is used for generating secret symmetric keys. In other words, it generates a SecretKey object from the input key specification (e.g. PBKDF2WithHmacSHA1). Note that your SecretKey instance inherits from which is Serializable and uses a default RAW encoding format.

Hence, you should not just toString() directly. As mentioned by Maeher, there is actually a getEncoded() method which returns the key as a byte array in its primary encoding format for viewing.

share|improve this answer
Thank you for the replies. Sorry about the 'off topic'. – user2256790 Apr 15 '14 at 16:17

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