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.

  • 4
    $\begingroup$ 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 docs.oracle.com/javase/7/docs/api/javax/crypto/spec/… what you are looking for is probably the output of the getEncoded() method. $\endgroup$
    – Maeher
    Apr 15, 2014 at 9:08
  • $\begingroup$ Your example "128 bit key" has only 64 bits once you convert it from hex to bytes. $\endgroup$ Apr 15, 2014 at 9:32

1 Answer 1


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 java.security.Key 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.


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