diff --git a/dist/jsOTP-es5.js b/dist/jsOTP-es5.js index 31bb8f6..1203be8 100644 --- a/dist/jsOTP-es5.js +++ b/dist/jsOTP-es5.js @@ -76,6 +76,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons epoch = Math.round(now / 1000.0); time = this.leftpad(this.dec2hex(Math.floor(epoch / this.expiry)), 16, "0"); shaObj = new jsSHA("SHA-1", "HEX"); + if (key.length % 2 !== 0) key = key.substring(0,key.length-1); shaObj.setHMACKey(key, "HEX"); shaObj.update(time); hmac = shaObj.getHMAC("HEX"); diff --git a/dist/jsOTP.js b/dist/jsOTP.js index 23a40c1..9ffa568 100644 --- a/dist/jsOTP.js +++ b/dist/jsOTP.js @@ -53,6 +53,7 @@ epoch = Math.round(now / 1000.0); time = this.leftpad(this.dec2hex(Math.floor(epoch / this.expiry)), 16, "0"); shaObj = new jsSHA("SHA-1", "HEX"); + if (key.length % 2 !== 0) key = key.substring(0,key.length-1); shaObj.setHMACKey(key, "HEX"); shaObj.update(time); hmac = shaObj.getHMAC("HEX"); diff --git a/js/jsOTP.js b/js/jsOTP.js index 4896746..a1ba36a 100644 --- a/js/jsOTP.js +++ b/js/jsOTP.js @@ -53,6 +53,7 @@ epoch = Math.round(now / 1000.0); time = this.leftpad(this.dec2hex(Math.floor(epoch / this.expiry)), 16, "0"); shaObj = new jsSHA("SHA-1", "HEX"); + if (key.length % 2 !== 0) key = key.substring(0,key.length-1); shaObj.setHMACKey(key, "HEX"); shaObj.update(time); hmac = shaObj.getHMAC("HEX");