Toggle navigation
Toggle navigation
This project
Loading...
Sign in
tools
/
totp-key
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
lintry
2017-06-22 10:51:36 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6425f1976f711fdb37550e9cb4f0c3a5b4b9a751
6425f197
1 parent
2a3bb598
调整测试代码
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
3 deletions
package.json
test/authenticator.test.js
test/otpauth.test.js
test/otplib.test.js
package.json
View file @
6425f19
{
"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"
}
}
...
...
test/authenticator.test.js
View file @
6425f19
...
...
@@ -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
);
...
...
test/otpauth.test.js
0 → 100644
View file @
6425f19
/**
* 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
test/otplib.test.js
0 → 100644
View file @
6425f19
/**
* 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
Please
register
or
login
to post a comment