Use generatedKeyPair to sign #140
-
Hi, I'm trying to use this library to sign and then encrypt a token. I could successfully generate the private/public key pair but I wasn't able to use to sign my token. `const { default: SignJWT } = require('jose/jwt/sign') describe('new jose', () => { it('sign', async () => { I really appreciate any help you can give me |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Attempting to sign using ES256 (Elliptic Curve Key based algorithm) with a key generated for PS256 (RSA based algorithm)? |
Beta Was this translation helpful? Give feedback.
-
formatting this for future readers: const { default: SignJWT } = require('jose/jwt/sign')
const { default: parseJwk } = require('jose/jwk/parse')
const { default: generateKeyPair } = require('jose/util/generate_key_pair')
describe('new jose', () => {
it('sign', async () => {
const prkey = await parseJwk({
alg: 'ES256',
crv: 'P-256',
kty: 'EC',
d: 'VhsfgSRKcvHCGpLyygMbO_YpXc7bVKwi12KQTE4yOR4',
x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo'
})
// const jwk = j.JWK.generateSync('EC')
// console.log(JWK private\n, jwk.toJWK(true));
// console.log(JWK public\n, jwk.toJWK());
const {privateKey, publicKey} = await generateKeyPair('PS256')
const jwt = await new SignJWT({ 'urn:example:claim': true })
.setProtectedHeader({ alg: 'ES256' })
.setIssuedAt()
.setIssuer('urn:example:issuer')
.setAudience('urn:example:audience')
.setExpirationTime('2h')
.sign(privateKey)
console.log(jwt)
})
}) |
Beta Was this translation helpful? Give feedback.
Attempting to sign using ES256 (Elliptic Curve Key based algorithm) with a key generated for PS256 (RSA based algorithm)?