Error using base32 encoding (browser support)
See original GitHub issueHi everybody,
I am using speakeasy in an Ember application with ember-browserify addon: https://www.npmjs.com/package/ember-browserify
Just encountered that the base32 encoding seems to not work at all. Considering the following code:
var secret = speakeasy.generateSecret(); // default length is 32
var secretKey = secret.base32;
var token = speakeasy.totp({
secret: secretKey,
encoding: 'base32'
});
So, just a secret generation and subsequent using it to create a new token leads to the following error:
“list” argument must be an Array of Buffers
The same issue with the speakeasy.totp.verify() method.
I’ve found the reason in the following code from index.js (lines 39-42):
// convert secret to buffer
if (!Buffer.isBuffer(secret)) {
secret = encoding === 'base32' ? base32.decode(secret)
: new Buffer(secret, encoding);
}
The base32.decode(secret)
returns an array and not a Buffer.
I’ve changed the code and got it working:
// convert secret to buffer
if (!Buffer.isBuffer(secret)) {
secret = encoding === 'base32' ? new Buffer(base32.decode(secret)) : new Buffer(secret, encoding);
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10
Top Results From Across the Web
base32-browser - npm
Start using base32-browser in your project by running `npm i ... Base 32 is between hexadecimal notation and Base 64 encoding.
Read more >1250113 – coreutils doesn't include a base32 binary
Description of problem: coreutils includes a base64 encoder, but no base32 (or base16). The base32 encoding is very useful for converting OTP ...
Read more >base32 image for img tag - Stack Overflow
If you mean the browser isn't displaying the image, all it means is that the browser doesn't support base32. I have the same...
Read more >Generating Base32 string examples - Yubico Support
MacOS and Ubuntu. Run the following command in a terminal to generate a 64 character Base32 random string: $ LC_ALL=C tr -dc 'A-Z2 ......
Read more >Base32 Encode - Code Beautify
Online Base32 Encode tool is to encode base32 your String using Base32 Encoder. Convert String, File and load URL.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mikepb & @markbao No problem, thanks for the update anyway, sometimes it’s nice just to know that the project/issue hasn’t been forgotten about and there are people “on-it”. 👍
Just thought of a more permanent fix. Instead of detecting whether the base32 returns a buffer, always import the client version and have speakeasy initialize a buffer with byte array.