-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJwtConst.cs
More file actions
34 lines (25 loc) · 1.01 KB
/
JwtConst.cs
File metadata and controls
34 lines (25 loc) · 1.01 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
using System.Security.Cryptography;
using Microsoft.IdentityModel.Tokens;
namespace SocialAPI;
public static class JwtConst
{
private static readonly string AppDomain = "cs-notes.com";
public static readonly string Issuer = AppDomain;
public static readonly string Audience = AppDomain;
// TODO: Replace with key from file (ideally asymmetric)
public static readonly SymmetricSecurityKey Key = new (new byte[256]);
public static readonly ECDsaSecurityKey PublicKey = LoadKey("./public.pem");
public static readonly ECDsaSecurityKey PrivateKey = LoadKey("./private.pem");
private static ECDsaSecurityKey LoadKey(string path)
{
var ed = ECDsa.Create();
if (!File.Exists(path))
{
throw new FileNotFoundException($"Private key at path {path} was not found.");
}
var privateKeyContent = File.ReadAllText(path);
ed.ImportFromPem(privateKeyContent);
var key = new ECDsaSecurityKey(ed);
return key;
}
}