feat: jwt application
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user