Last active
September 23, 2016 15:18
-
-
Save rice10t/1a055c39f14e8e7ecfffe1503ce7f3c9 to your computer and use it in GitHub Desktop.
token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
/** | |
* 暗号論的擬似乱数生成器を使ってトークンを生成する | |
*/ | |
function genToken() { | |
return new Promise((resolve, reject)=> { | |
crypto.randomBytes(32, (err, buf) => { | |
if (err) { | |
reject(err); | |
return; | |
} | |
resolve(buf.toString('hex')); | |
}); | |
}); | |
} | |
Promise.all([genToken(), genToken(), genToken()]) | |
.then(console.log); | |
// [ 'ac45be5a0ccf851165eec4be8a673bd561758ad4abe49682ccc74630ec3aba73', | |
// 'd80f95e8881a36aa159b6d1587e705fd202140ca3fadc9803d00eaafe04979c2', | |
// '6de18a5f116c0bf785f7e7c644bdb35b044d38408e6394f0ebe10db8526d9013' ] | |
module.exports = genToken; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment