0

I have been playing around with the code found here. I'm getting things like

UKepQT7tW8mGtOJzNaLV2X+Ij/E=

when I view the hashed password using

String t = base64EncoderDecoder.encodeAsString(f.generateSecret(spec).getEncoded());

for my hashed password. Should it have symbols like +/= ? Also I expected the hash to be longer. Did I screw something up?

1 Answer 1

3

Should it have symbols like +/= ?

Well, according to what should have been the first Google result (the Wikipedia article on Base64 encoding), + and / are valid symbols that are mapped to 62 and 63 respectively. = is a padding character.

Also I expected the hash to be longer.

Why? It's just a consequence of the encoding method you're using. Encoding something in base 16 will take 50% more characters (since it takes 1 character per 4 bits, instead of 1 character per 6 bits). From the very reference you cite:

// SHA-1 generates 160 bit hashes, so that's what makes sense here

160 bits results in a 27 character Base64 encoding (160/6 ~= 27), which is what you have, so it seems reasonable to me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.