speakeasy
speakeasy copied to clipboard
(some) hex encoded keys not parsed correctly
I could not generate correct totp codes. Was using a hex encoded key. I think there is a problem handling some special ASCII chars in my hex key. Anyway here is the fix that worked for me:
Change line: key = speakeasy.hex_to_ascii(key); into: key = new Buffer(speakeasy.hex_to_ascii(key), 'ascii');
Perhaps it's even better to change this line instead: var hmac = crypto.createHmac('sha1', new Buffer(key)); into var hmac = crypto.createHmac('sha1', new Buffer(key, 'ascii'));
That way it will also handle all 'ascii' encoded keys correctly I guess... Although you better test what this gives when passing a base32 coded key then;-)