33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using System.Security.Cryptography;
|
|
|
|
namespace AuthHex;
|
|
|
|
/// <summary>
|
|
/// Utility class to generate RSA key pairs for JWT authentication.
|
|
/// Run this once to generate keys and copy them to appsettings.json
|
|
/// </summary>
|
|
public class RsaKeyGenerator
|
|
{
|
|
public static void GenerateAndPrintKeys()
|
|
{
|
|
using var rsa = RSA.Create(2048);
|
|
|
|
var privateKey = rsa.ToXmlString(true); // includes private key
|
|
var publicKey = rsa.ToXmlString(false); // public key only
|
|
|
|
Console.WriteLine("=== RSA Private Key (Keep this SECRET!) ===");
|
|
Console.WriteLine(privateKey);
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine("=== RSA Public Key ===");
|
|
Console.WriteLine(publicKey);
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine("Copy the Private Key to appsettings.json -> Jwt:RsaPrivateKey");
|
|
Console.WriteLine("Copy the Public Key to appsettings.json -> Jwt:RsaPublicKey");
|
|
Console.WriteLine();
|
|
Console.WriteLine("IMPORTANT: Never commit the private key to source control!");
|
|
Console.WriteLine("Consider using Azure Key Vault or environment variables for production.");
|
|
}
|
|
}
|