Files
jsotp/src/base32.js
T
2017-06-30 13:11:18 +08:00

38 lines
874 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @module : BASE32 module to generate the random b32 key
* and decode the secret.
* @author : Gin (gin.lance.inside@hotmail.com)
*/
const nibbler = require("./nibbler/nibbler");
export class Base32 {
/*
* Base32 decode function
*
* @param {secret}
* @type {String}
* @desc input string
*
* @return {String}
*/
static decode(secret) {
return nibbler.b32decode(secret);
}
/*
* Base32 generate random b32 encoded string function
*
* @param {length}
* @type {int}
* @desc the length of random b32 encoded string
*
* @return {String}
*/
static random_gen(length=16) {
let random_str = Math.random().toString(36);
random_str = nibbler.b32encode(random_str);
return random_str.substring(0, length);
}
}