This commit is contained in:
Dhananjaya99
2026-07-08 11:11:50 +05:30
parent 2cd2741f77
commit de7b40a147
51 changed files with 6839 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
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.");
}
}