feat: jwt application

This commit is contained in:
2024-10-13 14:56:22 +07:00
parent a934952816
commit e9f32fc32e
11 changed files with 295 additions and 4 deletions

View File

@@ -4,10 +4,32 @@ namespace RsaKeyLoader;
public class KeyLoader
{
public void Generate(string path)
public static string PathString =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "auth-key");
public static RSA GetGeneratedKey()
{
if (File.Exists(PathString))
{
return LoadKey(PathString);
}
else
{
Generate(PathString);
return LoadKey(PathString);
}
}
public static void Generate(string path)
{
var rsaKey = RSA.Create();
var privateKey = rsaKey.ExportRSAPrivateKey();
File.WriteAllBytes(path, privateKey);
}
public static RSA LoadKey(string path)
{
var rsaKey = RSA.Create();
rsaKey.ImportRSAPrivateKey(File.ReadAllBytes(path), out _);
return rsaKey;
}
}