lintry

调整测试代码

{
"name": "totp-key",
"name": "kml-totp-key",
"version": "1.0.0",
"description": "创建基于TOTP的登录密钥所需要的方法",
"main": "index.js",
......@@ -23,5 +23,10 @@
"lodash": "^4.17.4",
"qr-image": "^3.2.0",
"speakeasy": "^2.0.0"
},
"devDependencies": {
"otpauth": "^2.2.3",
"otplib": "^4.0.6",
"sjcl": "^1.0.6"
}
}
......
......@@ -8,8 +8,9 @@ const fs = require('fs-extra');
const path = require('path');
//使用外部生成的密钥
let secret = 'vH6OdbUEjSukTqlDvW3TYdusjiOIkxRnAHNTjJewfZa5yNueG9wx1N9pJMFOmPAV';
let authenticator = new TOTP({algorithm: 'sha512'}).parse(secret);
// let secret = 'vH6OdbUEjSukTqlDvW3TYdusjiOIkxRnAHNTjJewfZa5yNueG9wx1N9pJMFOmPAV';
let secret = 'acnahbfX3bKa+EuhD7sR+MToc8d5rZ8Db7xh68ZUnBX3SPfhlHS/GeJ7SKEfcLTI';
let authenticator = new TOTP({algorithm: 'sha1'}).parse(secret);
console.log(chalk.cyan('totp的secret'));
console.log(secret, authenticator.totp_options);
......
/**
* Created by lintry on 2017/5/19.
*/
//用到了eval函数,不能在小程序内使用
const OTPAuth = require('otpauth');
let totp = new OTPAuth.TOTP({
'issuer': 'ACME',
'label': 'AzureDiamond',
'algorithm': 'SHA1',
'digits': 6,
'period': 30,
'secret': OTPAuth.Secret.fromB32('NB2W45DFOIZA')
});
// Generate TOTP token
let token = totp.generate();
// Validate TOTP token
let delta = totp.validate({
'token': token,
'window': 10
});
// Convert to Google Authenticator key URI
// otpauth://totp/ACME:AzureDiamond?issuer=ACME&secret=NB2W45DFOIZA&algorithm=SHA1&digits=6&period=30
let uri = totp.toString();
console.log(uri, delta, token)
\ No newline at end of file
/**
* Created by lintry on 2017/5/19.
*/
//用到了eval函数,不能在小程序内使用
const authenticator = require('otplib/authenticator').default;
console.log(authenticator)
authenticator.options.algorithm = 'sha1'
authenticator.options.encoding = 'base32'
const secret = authenticator.generateSecret();
const token = authenticator.generate('FA7HM4ZZG5AF4JSVHQ4XOVC6KFGVAMRZ');
const isValid = authenticator.check(123456, secret);
console.log(token, secret, isValid)
\ No newline at end of file