TirsvadCLI.PfxCertificate 0.2.0

dotnet add package TirsvadCLI.PfxCertificate --version 0.2.0
                    
NuGet\Install-Package TirsvadCLI.PfxCertificate -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TirsvadCLI.PfxCertificate" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TirsvadCLI.PfxCertificate" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="TirsvadCLI.PfxCertificate" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TirsvadCLI.PfxCertificate --version 0.2.0
                    
#r "nuget: TirsvadCLI.PfxCertificate, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=TirsvadCLI.PfxCertificate&version=0.2.0
                    
Install TirsvadCLI.PfxCertificate as a Cake Addin
#tool nuget:?package=TirsvadCLI.PfxCertificate&version=0.2.0
                    
Install TirsvadCLI.PfxCertificate as a Cake Tool

NuGet DownloadsContributorsForksStargazersIssuesLicenseLinkedIn

Logo Pfx Certificate Library

Overview

Pfx Certificate Library is a .NET tool designed to simplify the creation, management, and installation of self-signed certificates for use in development environments. It provides an easy-to-use API for generating certificates and managing their lifecycle.

Table of Contents

Features

  • Generate self-signed certificates with customizable properties.
  • Export certificates to .pfx files with private keys.
  • Install certificates into the local certificate store.
  • Remove certificates from the store by subject name.
  • Fully asynchronous API for modern .NET applications.

Getting Started

To get started with the Form library, you will need to install the library in your .NET project. You can do this using NuGet Package Manager or by adding the package reference directly to your project file.

Prerequisites

  • .NET 9.0 or later

Installation

To use the library, you will need to download and then add a reference to the library in your project. Follow the instructions below to install the library and get started.

Install via NuGet Package Manager Console

You can install the library using the NuGet Package Manager Console. Open the console and run the following command:

Install-Package TirsvadCLI.PfxCertificateManager
Install via Visual Studio NuGet Package Manager
  1. Open your project in Visual Studio.
  2. Right-click on your project in the Solution Explorer and select "Manage NuGet Packages".
  3. Search for "TirsvadCLI.PfxCertificateManager" in the NuGet Package Manager.
  4. Click "Install" to add the library to your project.
Install via .NET CLI

You can also install the library using the .NET CLI. Open a terminal and run the following command:

dotnet add package TirsvadCLI.PfxCertificateManager
Clone the repo

Repo size

If you want to clone the repository and build the library from source, you can do so using Git. Make sure you have Git installed on your machine. Then, run the following command in your terminal:

git clone git@github.com:TirsvadCLI/Dotnet.Lib.PfxCertificate.git

Usage

  1. Create a Self-Signed Certificate
    Use the CreateCertificateAsync method to generate a self-signed certificate and save it as a .pfx file:
    await CertificateManager.CreateCertificateAsync( 
        commonName: "MySubject",          // Common Name (CN) 
        organization: "MyOrganization",   // Organization (O)
        organizationUnit: "MyOrgUnit",    // Organizational Unit (OU) 
        country: "US",                    // Country (C)
        state: "MyState",                 // State (S)
        locality: "MyLocality",           // Locality (L)
        password: "MyPassword123!"        // Password for the .pfx file );
    
  2. Add a Certificate to the Store
    Use the AddCertificateAsync method to add a .pfx certificate to a specific certificate store:
    await CertificateManager.AddCertificateAsync( 
        pfxPath: "MySubject.pfx",        // Path to the .pfx file 
        password: "MyPassword123!",      // Password for the .pfx file 
        storeName: StoreName.My,         // Certificate store name (e.g., My, Root) 
        storeLocation: StoreLocation.CurrentUser // Store location (e.g., CurrentUser, LocalMachine) );
    
  3. Remove a Certificate from the Store
    Use the RemoveCertificateAsync method to remove a certificate from a specific store by its thumbprint:
     await CertificateManager.RemoveCertificateAsync( 
          thumbprint: "THUMBPRINT",        // Thumbprint of the certificate 
          storeName: StoreName.My,        // Certificate store name (e.g., My, Root) 
          storeLocation: StoreLocation.CurrentUser // Store location (e.g., CurrentUser, LocalMachine) );
    
  4. Display Certificate Details
    The DisplayCertificateDetails method is used internally to print certificate details to the console. You can use it to inspect certificates:
    var cert = new X509Certificate2("MySubject.pfx", "MyPassword123!");
    CertificateManager.DisplayCertificateDetails(cert);
    

Notes:

  • The CreateCertificateAsync method generates a self-signed certificate valid for 5 years by default.
  • The AddCertificateAsync and RemoveCertificateAsync methods are only supported on Windows for managing the certificate store.
  • Ensure you have the necessary permissions to access the certificate store when using AddCertificateAsync or RemoveCertificateAsync.

These examples demonstrate how to use the core features of the CertificateManager class. For more advanced usage, refer to the source code or extend the functionality as needed.

Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
    • Note: Before committing, ensure you have created appropriate tests for your changes. This helps maintain the quality and reliability of the project.
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Bug / Issue Reporting

If you encounter a bug or have an issue to report, please follow these steps:

  1. Go to the Issues Page
    Navigate to the GitHub Issues page.

  2. Click "New Issue"
    Click the green "New Issue" button to create a new issue.

  3. Provide Details

  • Title: Write a concise and descriptive title for the issue.
  • Description: Include the following details:
    • Steps to reproduce the issue.
    • Expected behavior.
    • Actual behavior.
    • Environment details (e.g., OS, .NET version, etc.).
  • Attachments: Add screenshots, logs, or any other relevant files if applicable.
  1. Submit the Issue
    Once all details are filled in, click "Submit new issue" to report it.

Your feedback is valuable and helps improve the project!

License

Distributed under the GPL-3.0 License.

Contact

Jens Tirsvad Nielsen - LinkedIn

Acknowledgments

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.0 152 4/23/2025
0.1.7 148 4/21/2025
0.1.6 150 4/21/2025
0.1.3 88 4/19/2025