panva / paseto

PASETO (Platform-Agnostic SEcurity TOkens) for Node.js with no dependencies
MIT License
428 stars 26 forks source link

question: How I create a secret key from a string? #2

Closed Nisgrak closed 4 years ago

Nisgrak commented 4 years ago

Hi!

I try to encrypt a payload with V2, I want to encrypt with key 'example', how can make it work?

Always I give the error

TypeError: v2.local secret key must be 256 bytes long symmetric key

Thanks and nice work 😄

panva commented 4 years ago

Hi @Nisgrak, you need a secret that's 256 bytes :) "example" isn't

Buffer.from('example').byteLength
// 7
Nisgrak commented 4 years ago

Okey, I add chars to the key then I have 256 bytes, but the error is the same.

Buffer.from('exampleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee').byteLength;
// 256
panva commented 4 years ago

🤦‍♂ sorry, 32 bytes, 256 bits. I fixed the error message in 1.0.2