Take the 2-minute tour ×
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.

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 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.

4  
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. –  Maeher Apr 15 at 9:08
    
Your example "128 bit key" has only 64 bits once you convert it from hex to bytes. –  CodesInChaos Apr 15 at 9:32
add comment

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.

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

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