zntrio / paseto

v3/v4 Golang PASETO implementation
Apache License 2.0
5 stars 1 forks source link

Test with paseto v4 from other languages #6

Closed DarkSorrow closed 1 month ago

DarkSorrow commented 1 month ago

Describe the bug I've been checking your library and wanted to try to encrypt in GO and decrypt in nodeJS. I've generated a token using a string as key that is 'vZ2WkkcJCeFXuQtpogPt2Ywof43X0h0x' Then i went on doing this in javascript

import { PasetoV4Local } from "paseto-browser";

const localKey = 'vZ2WkkcJCeFXuQtpogPt2Ywof43X0h0x';//generateKeys('local');

const token = 'v4.local.GeneratedToken';

try {
  let key = new TextEncoder("utf-8").encode(localKey);
  console.log(key)
  const paseto = new PasetoV4Local(key)
  const decrypted = await paseto.decrypt(token, key, {
    validatePayload: false,
  });
  console.log(decrypted);
} catch(err) {
    console.log(err)
}

It gave me this error 'Error: Invalid tag'

I tried another library that is paseto-ts and it gave me the same error, it seems the tag always differ from the go implementation. I'm not sure if i missuse something there but i didn't add any kind of custom things, here is my encrypt call

// account is a marshalled json
token, err := pasetov4.Encrypt(rand.Reader, "vZ2WkkcJCeFXuQtpogPt2Ywof43X0h0x", account, nil, nil)

Expected behavior Encrypting on go should still have a valid decode using other language libraries

DarkSorrow commented 1 month ago

Okay i figured it out, i needed to append the k4.local. then encode my key to base 64 to make it work. I suppose i need to test some new things still :D