Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws error if buffer is passed in secret #2

Closed
detj opened this issue Apr 22, 2015 · 1 comment
Closed

Throws error if buffer is passed in secret #2

detj opened this issue Apr 22, 2015 · 1 comment

Comments

@detj
Copy link

detj commented Apr 22, 2015

Passing buffer in secret doesn't work

var crypto = require('crypto');
var otp = require('otp')({
  secret: crypto.randomBytes(256);
});

console.log(otp.hotp());

throws the following error

/Users/detj/tmp/plivo-try/node_modules/otp/node_modules/thirty-two/lib/thirty-two/thirty-two.js:121
            throw new Error('Invalid input - it is not base32 encoded string');
                  ^
Error: Invalid input - it is not base32 encoded string
    at Object.exports.decode (plivo-try/node_modules/otp/node_modules/thirty-two/lib/thirty-two/thirty-two.js:121:16)
    at OTP.hotp (plivo-try/node_modules/otp/otp.js:65:58)
    at Object.<anonymous> (/Users/detj/tmp/plivo-try/otp.js:20:17)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Tried with node 0.12.2 and node 0.10.38

@detj detj changed the title Throws error is buffer is passed in secret Throws error if buffer is passed in secret Apr 22, 2015
@pipobscure
Copy link
Owner

Sorry for the late response. The reason for this is because passing in a buffer is in fact invalid.

This requires not a buffer, but rather a bas32 encoded string. If you want to generate a new secret, all you have to do is not pass it in during creation and it will then be available on the istance as secret.

var otp = require('otp')({});
console.log('Secret: ', otp.secret)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants