chriszarate / supergenpass

A free bookmarklet password generator.
https://chriszarate.github.io/supergenpass/
GNU General Public License v2.0
418 stars 160 forks source link

Cannot reproduce w/ openssl dgst -sha512 #70

Closed xrat closed 9 years ago

xrat commented 9 years ago

I was trying to reproduce passwords using a shell script such as https://github.com/lanzz/bash-supergenpass . It works for MD5 but not for SHA512. With MD5 in place (original code of lanzz's script) doing the test with test and example.com:

$ echo test | ./supergenpass.sh example.com
w9UbG0NEk7

If I change lanzz's code from

openssl -md5 -binary

to

openssl dgst -sha512 -binary

the result is

$ echo test | ./supergenpass.sh example.com
wNQ28JIARX

but it should be sJfoZg3nU8.

xrat commented 9 years ago

Found the cause: base64 as used in lanzz's script is wrapping lines and hence introducing newlines if used in conjunction with openssl dgst -sha512. Since the base64 of a sha512 is over 80 chars long we need to use base64 -w0 to disable wrapping. Using for instance

hash=$(echo -n "$hash" | openssl dgst -sha512 -binary | base64 -w0 | tr +/= 98A)

all method sha512 tests from https://github.com/chriszarate/supergenpass-lib/blob/master/tests/simple.js are OK.