Likespace-Kft / wotp

MIT License
0 stars 0 forks source link

Unable to verify/gen #1

Open badoge opened 1 year ago

badoge commented 1 year ago

I'm testing out the library in a browser but I was not able to get it to work, I keep getting this error:

Failed to execute 'importKey' on 'SubtleCrypto': The provided value is not of type '(ArrayBuffer or ArrayBufferView or JsonWebKey)'.

I tried converting the key into an ArrayBuffer but the 2FA codes that got generated did not match the codes in Google Authenticator

Kebab11noel commented 1 year ago

Make sure the key passed to the function is - like the error says - either an ArrayBuffer, ArrayBufferView or JsonWebKey, if the issue still persists please share the code you've tried.

badoge commented 1 year ago

I already tried converting the secret into an ArrayBuffer, the problem was that the generated codes were wrong

  let enc = new TextEncoder();
  let buffer = enc.encode("YZ2DAQEUT477APT5");
  console.log(buffer.buffer);
  let code = await totp.gen(buffer.buffer);
  console.log(code);

image

Kebab11noel commented 1 year ago

Secrets shown in ASCII are usually base32 encoded, so make sure you decode them like base32 (a very good lib is thirty-two), however TextEncoder.encode returns the UTF-8 bytes of the input.

rodbs commented 8 months ago

I understand buffer is deprecated. Could anyone set a working example of how to generate the key (in ArayBuffer?) to generate a totp, and then to verify it? thx