Skip to content

Custom symetric key doesn't seem to work, no output [Question] #14

@Extarys

Description

@Extarys

I'm trying to generate a key and use that for the token, but everything below the encrypt method doesn't work.

"paseto.js": "^0.1.3",

const crypto = require("crypto")
const Paseto = require("paseto.js")
const uuid = require("uuid/v4")

async function generateToken() {
	const message = {
		tokenId: uuid(), // Token Id
	}

	// Generate key
	//const key = crypto.randomBytes(32)

	const keyRaw = Buffer.from(
		"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
		"hex"
	)

	const sk = new Paseto.SymmetricKey(new Paseto.V2())

	await sk.inject(keyRaw)
        console.log(sk) // <-- output key object
	const encoder = sk.protocol()

	const token = await encoder.encrypt(message, sk)

        // No output below --v--
	console.log(message)
	console.log(token)

	return token
}
generateToken()

Output:

# node auth.js 
SymmetricKey {
  INFO_ENCRYPTION: 'paseto-encryption-key',
  INFO_AUTHENTICATION: 'paseto-auth-key-for-aead',
  _protocol: V2 { _repr: 'v2', _constants: { SYMMETRIC_KEY_BYTES: 32 } },
  _key:
   <Buffer de ad be ef de ad be ef de ad be ef de ad be ef de ad be ef de ad be ef de ad be ef de ad be ef> }

It may just be me but I find it as difficult as JWT to use for now 😆

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions