Skip to content
Snippets Groups Projects
Commit 1cf6e292 authored by Klaus Fischer's avatar Klaus Fischer
Browse files

...Stopping key generator - out of scope

parent f6ecb962
No related branches found
No related tags found
1 merge request!24AutoReject planning#594
......@@ -5,10 +5,9 @@ using Microsoft.IdentityModel.Tokens;
namespace FitConnect.SelfServicePortal;
public class KeyGenerator {
private RSA _signingRsa;
private RSA _encryptionRsa;
public KeyGenerator() {
_encryptionRsa = RSA.Create();
_encryptionRsa = RSA.Create();
......@@ -19,19 +18,18 @@ public class KeyGenerator {
// Create a new RSA key
var rsa = RSA.Create();
var certificate = X509Certificate2.CreateFromPem(
);
certificate.PublicKey = rsa.ExportRSAPublicKey();
// Create a new self-signed certificate
var certificate = new X509Certificate2(
rsa, // RSA key
HashAlgorithmName.SHA256, // Signature algorithm
"CN=MyCertificate", // Subject name
"MyCertificate", // Friendly name
X509KeyUsageFlags.DataEncipherment,
DateTime.UtcNow, // Not before
DateTime.UtcNow.AddYears(1) // Not after
);
X509Certificate2 certificate = null!;
// certificate.PublicKey = rsa.ExportRSAPublicKey();
// // Create a new self-signed certificate
// var certificate = new X509Certificate2(
// rsa, // RSA key
// HashAlgorithmName.SHA256, // Signature algorithm
// "CN=MyCertificate", // Subject name
// "MyCertificate", // Friendly name
// X509KeyUsageFlags.DataEncipherment,
// DateTime.UtcNow, // Not before
// DateTime.UtcNow.AddYears(1) // Not after
// );
// Get the certificate chain as a byte array
byte[] certificateChain = certificate.Export(X509ContentType.Cert);
......@@ -40,21 +38,21 @@ public class KeyGenerator {
string x5c = Convert.ToBase64String(certificateChain);
// Create a JWK from the RSA key and certificate chain
var jwkKey = new JsonWebKey
{
var jwkKey = new JsonWebKey {
Kty = "RSA",
Alg = SecurityAlgorithms.RsaSha256Signature,
Use = "sig",
Kid = "rsa-key",
X5c = { x5c }
X5c = { x5c }
};
// Output the JWK key
Console.WriteLine(jwkKey.ToString());
return jwkKey;
}
public JsonWebKey GenerateEncryptionKey() {
var certificate = new X509Certificate2(_encryptionRsa);
X509Certificate2 certificate = null!; // new X509Certificate2(_encryptionRsa);
// Get the certificate chain as a byte array
byte[] certificateChain = certificate.Export(X509ContentType.Cert);
......@@ -63,13 +61,12 @@ public class KeyGenerator {
string x5c = Convert.ToBase64String(certificateChain);
// Create a JWK from the RSA key and certificate chain
var jwkKey = new JsonWebKey
{
var jwkKey = new JsonWebKey {
Kty = "RSA",
Alg = SecurityAlgorithms.RsaSha256Signature,
Use = "sig",
Kid = "rsa-key",
X5c = new[] { x5c }
X5c = { x5c }
};
return jwkKey;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment