如何解密JWE用ECD(ECDH-ES+ A128KW)算法加密。

发布于 2025-02-11 07:08:14 字数 205 浏览 1 评论 0原文

我一直在寻找C#中的一种方法来解密JWE令牌由我的OpenID Connect Provider加密ECDH-ES+A128KW。我已经与OIDC提供商分享了EC公钥,他们给我发送了使用共享公钥加密的JWE。我想使用我安全存储的私钥从JWE有效载荷中解密并提取信息。 一段时间以来,我一直在寻找C#中的合适的解密库。我的应用程序是.NET 5应用程序,并在Linux上运行。 任何帮助都高度赞赏。

I have been looking for a way in C# to decrypt JWE tokens encrypted with ECDH-ES+A128KW by my OpenId Connect provider. I have shared the EC public key with OIDC provider and they send me a JWE encrypted using the shared public key. I want to decrypt and extract information from JWE payload using the private key which I have stored securely.
I have been looking for a proper decryption library in C# for a while. My application is a .Net 5 application and runs on Linux.
Any help highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2025-02-18 07:08:14

假设它会帮助某人,回答这个问题。
您可以使用以下代码解密JW,

 using Jose;

 var privateKey = new Jwk(
                crv: encryptionPublicKey.crv,
                x: "y_0F1OlwlIj0VVDbWF2D3JnHqryJK58CExQXqJr3e5s",
                y: "Av4X6ew_hQLmL3qgJJjKcqJcTftpsDk0VLwFLBEzEIE",
                d: "k44uec9XUofhcGUD6mwf-1krn4nQJ5q3TWDwg8wkTFY",
        );
 string decryptedToken = JWT.Decode(token, privateKey);

如果您仍然将JWT作为解密,则可以使用以下方法读取令牌

 JwtSecurityTokenHandler handler = new();
 var jwtSecToken = handler.ReadJwtToken(decryptedIdToken);

Answering this question assuming it would help someone.
You can decrypt the JWS using the following code

 using Jose;

 var privateKey = new Jwk(
                crv: encryptionPublicKey.crv,
                x: "y_0F1OlwlIj0VVDbWF2D3JnHqryJK58CExQXqJr3e5s",
                y: "Av4X6ew_hQLmL3qgJJjKcqJcTftpsDk0VLwFLBEzEIE",
                d: "k44uec9XUofhcGUD6mwf-1krn4nQJ5q3TWDwg8wkTFY",
        );
 string decryptedToken = JWT.Decode(token, privateKey);

If you still get a JWT as a decryptedToken, you can read the token using following method

 JwtSecurityTokenHandler handler = new();
 var jwtSecToken = handler.ReadJwtToken(decryptedIdToken);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文