jiangts / JS-OTP

100% Javascript Implementation of HOTP and TOTP for Two-Factor Authentication.
https://jiangts.github.io/JS-OTP
MIT License
256 stars 70 forks source link

Stop SHA errors related to: Token Length Exception #12

Closed blizzardengle closed 3 years ago

blizzardengle commented 4 years ago

Some websites and providers generate a secret key that technically is not the proper length to use in generating a OTP. If you pad from the left when such a secret key is detected you can fix the key length without altering the output. This is needed for example with websites like Amazon that currently return a 52 character secret key.

NOTE: This changes was only done in the jsOTP-es5.js and jsOTP.js files. These files still need to be minified and then minified gzipped.

gmihaly-lmi commented 3 years ago

Hi, Your fix does not seem to work. My suggestion is this: var checklength = bits.length - bits.length % 8; i = 0; while (i + 4 <= checklength) { chunk = bits.substr(i, 4); hex = hex + parseInt(chunk, 2).toString(16); i += 4; }

Based on that in a working totp generator the last standalone HEX digit is ignored.