dotnet / dotnet/AspNetCore.Docs

Need C# Examples of How to Generate Certificates

Open
#26,613 1 comment 0 reactions 0 assignees View on GitHub
doc-idea Source - Docs.ms
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 3h
Merged PRs (30d)
97

Description

The PowerShell examples of how to generate certificates are helpful, but it took me a week or two to figure out how to produce the equivalent C# code which generates client certificates signed by the root CA. I had to combine articles across StackOverflow, blog posts, and CodeProject articles to create a function which reproduces what the PowerShell command does. Here is a repro of the exact code needed in my case, and it's not easy as you can see.
Generating these certificates via C# requires in-depth research into certificate and even the binary codes used to generate certain extensions. It would be great for MS to document this process or even build a library to streamline this and make it similar to the inputs and outputs of the PowerShell commands. Here is my runnable code which reproduces the PowerShell commands [here](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/certauth?view=aspnetcore-6.0#create-child-certificate-from-root-certificate):

[https://dotnetfiddle.net/L8bwzO](https://dotnetfiddle.net/L8bwzO)

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 35b7960d-6de5-78ee-bc45-d7218239bbc8
* Version Independent ID: d2db534b-198a-dc99-5b5a-0525582d39ac
* Content: [Configure certificate authentication in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/certauth?view=aspnetcore-6.0#create-child-certificate-from-root-certificate)
* Content Source: [aspnetcore/security/authentication/certauth.md](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/security/authentication/certauth.md)
* Product: **aspnet-core**
* Technology: **aspnetcore-security**
* GitHub Login: @blowdart
* Microsoft Alias: **bdorrans**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.