Skip to content

Encryption with "alg" ECDH_ES* #197

Answered by panva
giovanni9793 asked this question in Q&A
Discussion options

You must be logged in to vote

What passage am I doing wrong?

A little bit in everything.

  • ECDH-ES(+*) is a public key based encryption. You're passing a secret key.
  • let the library generate the ephemeral key, don't do it yourself.
  • ECDH_ES_A128KW is not a registered algorithm, ECDH-ES+A128KW is.
  • secp256r1 is not a curve registered for JOSE use.
import { parseJwk } from 'jose/jwk/parse'
import { CompactEncrypt } from 'jose/jwe/compact/encrypt'

const recipientPublicKey = {
  "kty": "EC",
  "crv": "P-256",
  "x": "Eb3RtGgBGOEz33yu46aha_RU6pyBaYNlu6SawlWGGHQ",
  "y": "tUncttzF6Ud4Abfn1N2A1Rz2MBbJSdI0zuKS28BNb-U"
}

const alg = 'ECDH-ES'

const publicKey = await parseJwk(recipientPublicKey, alg)

const token = await new C…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@giovanni9793
Comment options

@panva
Comment options

@giovanni9793
Comment options

Answer selected by giovanni9793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants