-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
browserify version of jsopt #3
Comments
/* Copyright Brian Turek 2008-2017 Several functions taken from Paul Johnston this one is working well both in nodejs and IE,chrome and so on in node: in browser: <script type='text/javascript' src='xxx.js'> var otpObj=new jsOTP; var number=optObj.hotp('secret',count); var number1=optObj.totp('secret',count); </script> |
Hy, Thanks for your information but i'll we create new version with |
function hotp(key, count, digitLength,algimType) {
if(!algimType){
algimType='SHA-1';
}
var shaObj = new jsSHA(algimType, "HEX");
shaObj.setHMACKey(key, "TEXT");
count =count.toString(16);
if(count.length<16){
var tmpZero='0';
count=tmpZero.repeat(16-count.length)+count;
}
shaObj.update(count);
var hash = shaObj.getHMAC("HEX");
var offset = Math.abs(parseInt(hash.substr(38, 2), 16));
offset = (offset & 0x0F)*2;
var trucateValue = "0x" + hash.substr(offset, 8);
trucateValue = Math.abs(parseInt(trucateValue)) & 0x7FFFFFFF;
if (!digitLength || digitLength <= 0 || digitLength > 6) {
digitLength = 6;
}
var hotpValue=(trucateValue % (Math.pow(10 , digitLength))).toString();
var lengthDiff=digitLength-hotpValue.length;
if(lengthDiff){
var tmpZero='0';
hotpValue=tmpZero.repeat(lengthDiff)+hotpValue;
}
return hotpValue;
}
and about the jsSHA,you can find it by google 'jsSHA'
The text was updated successfully, but these errors were encountered: