GithubHelp home page GithubHelp logo

stuck on key length error about paseto HOT 10 CLOSED

panva avatar panva commented on June 18, 2024
stuck on key length error

from paseto.

Comments (10)

lu-zen avatar lu-zen commented on June 18, 2024

symmetricKeySize and asymmetricKeySize props of the KeyObject generated are both undefined.
Running node 12.16.1

from paseto.

panva avatar panva commented on June 18, 2024

https://nodejs.org/docs/latest-v12.x/api/crypto.html#crypto_keyobject_symmetrickeysize

KeyObjects do not have ‘byteLength’ as your code suggests.

I can’t reproduce this report.

from paseto.

lu-zen avatar lu-zen commented on June 18, 2024
require("crypto")
  .createSecretKey( Buffer.from("...", "base64") )
  .symmetricKeySize // undefined

Wrong code srry. The symmetricKeySize property is undefined. Running the same code on console returns its size. Any idea?

from paseto.

panva avatar panva commented on June 18, 2024

The code without the property is not using node 12, it’s likely v11 which used symmetricSize property. V11 is not supported by this module tho.

from paseto.

lu-zen avatar lu-zen commented on June 18, 2024

Node 12.16.1. Anyway it's something related to node.

from paseto.

panva avatar panva commented on June 18, 2024

You asked if I had an idea. Your console is node 12, whatever else you run the code in where it doesn’t work is a different version.

Put a console.log(process.versions) in the code and see the difference.

from paseto.

lu-zen avatar lu-zen commented on June 18, 2024

@panva just to check... The func checkKey receives two args (header, key), but key is passed as the first argument here:

/lib/V2/encrypt.js

  payload = checkPayload(payload)
  key = checkKey(key) // <<

/lib/V2/help/symmetric_key_check.js

function checkKey (header, key) {
  if (!(key instanceof KeyObject)) {
    key = createSecretKey(key)
  }

  if (key.type !== 'secret' || key.symmetricKeySize !== 32) {
    throw new TypeError(`${header} secret key must be 32 bytes long symmetric key`)
  }

Is this correct?
I think this combined to the wrong type of symmetricKeySize popping on vscode confused me 😆 .

from paseto.

panva avatar panva commented on June 18, 2024

Yes it is used correctly. Your vscode is running node 11, am i right?

from paseto.

lu-zen avatar lu-zen commented on June 18, 2024

Only one node version, latest lts. Idk which lib included node typing. Now it works, just tired I guess. thanks for you help

from paseto.

panva avatar panva commented on June 18, 2024

I don't see what typings have to do with runtime results but okay.

from paseto.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.