davalapar / crypto

/dev/urandom, HOTP, TOTP, Scrypt
1 stars 0 forks source link

@davalapar/crypto

Latacora 2018 Recommendations

randomBytes

const { randomBytes } = require('@davalapar/crypto');
console.log(randomBytes.sync(32));
randomBytes.async(32).then(console.log);

Base32-encoded HOTP key

const { hotpKey } = require('@davalapar/crypto');
const key = hotpKey();

HMAC-based one-time password (HOTP)

const { hotpCode, hotpKey } = require('@davalapar/crypto');
const key = hotpKey();
const code = hotpCode('sha1', key, true, 1);

Time-based one-time password (TOTP)

const { totpCode, totpVerify, hotpKey } = require('@davalapar/crypto');
const key = hotpKey();
const timeCounter = Math.floor(Math.round(Date.now() / 1000) / 30);
const code = totpCode('sha1', key, true, timeCounter);
const isCodeValid = totpVerify('sha1', key, true, code);

Accepted algorithms for HOTP & TOTP

Scrypt

const { scryptKey, scryptSalt } = require('./index');
const salt = scryptSalt();
const derivedKey = await scryptKey('password', salt);
console.log('salt:', salt.toString('hex'));
console.log('key:', derivedKey.toString('hex'));

References

License

MIT | @davalapar