Reputation: 317
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?
Upvotes: 0
Views: 181
Reputation: 81134
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.
Upvotes: 3