-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJsonWebEncryptionExtension.cs
More file actions
55 lines (45 loc) · 1.97 KB
/
JsonWebEncryptionExtension.cs
File metadata and controls
55 lines (45 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace PCPPlugins.BusinessLayer.Extensions
{
using System;
using System.Collections.Generic;
using System.Security.Claims;
using Microsoft.IdentityModel.Tokens;
using Microsoft.IdentityModel.JsonWebTokens;
public class JsonWebEncryptionExtension
{
private string PublicKeySign { get; set; }
private string PrivateKeyEncrypt { get; set; }
public IDictionary<string, object> Claims { get; }
public ClaimsIdentity ClaimsIdentity { get; }
public Exception Exception { get; }
public string Issuer { get; }
public bool IsValid { get; }
public IDictionary<string, object> PropertyBag { get; }
public SecurityToken SecurityToken { get; }
public CallContext TokenContext { get; }
public string TokenType { get; }
public JsonWebEncryptionExtension(string _publicKeySign, string _privateKeyEncrypt)
{
PublicKeySign = _publicKeySign;
PrivateKeyEncrypt = _privateKeyEncrypt;
}
private static TokenValidationResult DecryptAndValidateJwe(string token, SecurityKey signingKey, SecurityKey encryptionKey)
{
var handler = new JsonWebTokenHandler();
TokenValidationResult result = handler.ValidateToken(
token,
new TokenValidationParameters
{
ValidAudience = "api1",
ValidIssuer = "https://idp.example.com",
// public key for signing
IssuerSigningKey = signingKey,
// private key for encryption
TokenDecryptionKey = encryptionKey
});
return result;
}
}
}
//https://stackoverflow.com/questions/49328317/how-to-decrypt-jwe-source-encrypted-with-rsa1-5-a256cbc-hs512-in-c
//https://www.scottbrady91.com/c-sharp/json-web-encryption-jwe-in-dotnet-core