lintry

调整生成密钥方法

......@@ -2,15 +2,24 @@
* Created by lintry on 2017/5/19.
*/
const _ = require('lodash'),
crypto_utils = require('kml-crypto-utils'),
speakeasy = require('speakeasy'),
Authenticator = require('./authenticator');
/**
* 生成密钥并加密
* @return {*}
*/
const createSecret = function () {
return crypto_utils.AESEncode(speakeasy.generateSecret({length: 20}).base32);
};
const TOTP = function (options) {
if (!(this instanceof TOTP)) {
return new TOTP(options)
}
const _ = require('lodash'),
crypto_utils = require('kml-crypto-utils'),
speakeasy = require('speakeasy'),
Authenticator = require('./authenticator');
options = options || {};
......@@ -21,14 +30,6 @@ const TOTP = function (options) {
};
/**
* 生成密钥并加密
* @return {*}
*/
this.createSecret = function() {
return crypto_utils.AESEncode(speakeasy.generateSecret({length: 20}).base32);
};
/**
* 解析密钥
* @param secret
* @return {Authenticator}
......@@ -40,4 +41,7 @@ const TOTP = function (options) {
return this;
};
TOTP.createSecret = createSecret;
TOTP.prototype.createSecret = createSecret;
module.exports = TOTP;
\ No newline at end of file
......
......@@ -7,6 +7,8 @@ const chalk = require('chalk');
const fs = require('fs-extra');
const path = require('path');
console.log(chalk.magenta('new secret ' + TOTP.createSecret()));
//使用外部生成的密钥
// let secret = 'vH6OdbUEjSukTqlDvW3TYdusjiOIkxRnAHNTjJewfZa5yNueG9wx1N9pJMFOmPAV';
let secret = 'acnahbfX3bKa+EuhD7sR+MToc8d5rZ8Db7xh68ZUnBX3SPfhlHS/GeJ7SKEfcLTI';
......