dvsekhvalnov / jose-jwt

Ultimate Javascript Object Signing and Encryption (JOSE), JSON Web Token (JWT) and Json Web Keys (JWK) Implementation for .NET and .NET Core
MIT License
921 stars 183 forks source link

How to use a JWK as a public key and encrypt a JWE using it #205

Closed shaiArn closed 1 year ago

shaiArn commented 1 year ago

Hi @dvsekhvalnov, thank you for this helpful library.

I'm getting JWK, and I need to use it to encrypt a JWE. After creating the JWK with Jwk.FromJson(), I want to use it as a public key for encrypting a JWE. If I understand correctly the encryption key in the JWE.Encrypt() method is the following argument: IEnumerable<JweRecipient> recipients

Is there a way to convert JWK to the needed type?

dvsekhvalnov commented 1 year ago

Hi @shaiArn ,

recipients is list of recipients for RFC 7516 JSON encoding. You specify a key per recipient, you can find examples within https://github.com/dvsekhvalnov/jose-jwt#encrypting-using-json-serialization (see second code snippet).

You don't need to convert Jwk to anything else, just pass it as key argument.