From 6fa3656cfc4f2d5d8e368b8b69c16673a96aff67 Mon Sep 17 00:00:00 2001 From: damienbod Date: Wed, 29 Jan 2020 10:20:26 +0100 Subject: [PATCH 1/3] CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 388784b..1ae8bb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Certificate Manager change log + +## 2020-01-29 version 1.0.3 +* private key pem exports +* private key import with certificate + ## 2020-01-27 version 1.0.2 * Small fixes for RSA certificates KeySize From 588a32ab1fc6b0efa5d184e1291298a9f8ffc4ad Mon Sep 17 00:00:00 2001 From: damienbod Date: Wed, 29 Jan 2020 10:22:21 +0100 Subject: [PATCH 2/3] updating version --- Documentation.md | 2 +- README.md | 2 +- src/CertificateManager/CertificateManager.csproj | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation.md b/Documentation.md index 43944bc..eaf326f 100644 --- a/Documentation.md +++ b/Documentation.md @@ -19,7 +19,7 @@ Certificate Manager is a package which makes it easy to create certificates (cha Add the NuGet package to the your project file ``` - + ``` The NuGet packages uses dependency injection to setup. In a console application initialize the package as follows: diff --git a/README.md b/README.md index 311e16e..d5efe80 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Add the NuGet package to the your project file ``` - + ``` The NuGet packages uses dependency injection to setup. In a console application initialize the package as follows: diff --git a/src/CertificateManager/CertificateManager.csproj b/src/CertificateManager/CertificateManager.csproj index 47c782f..df7d0b3 100644 --- a/src/CertificateManager/CertificateManager.csproj +++ b/src/CertificateManager/CertificateManager.csproj @@ -11,11 +11,11 @@ Certificate Manager is a package which makes it easy to create certificates (chained and self signed) which can be used to in client server authentication and IoT Devices like Azure IoT Hub certificate authentication mtls pfx cer pem cert crt - small fixes for RSA certificates + private key, public certificate pem exports 2020 damienbod true damienbod - 1.0.2 + 1.0.3 From a7e6ec26bca8af7ae1866364fbdb26839bae601f Mon Sep 17 00:00:00 2001 From: damienbod Date: Wed, 29 Jan 2020 10:33:46 +0100 Subject: [PATCH 3/3] docs import export pem --- Documentation.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Documentation.md b/Documentation.md index eaf326f..711ee7d 100644 --- a/Documentation.md +++ b/Documentation.md @@ -382,6 +382,69 @@ var deviceVerifyPublicKey = importExportCertificate.ExportCertificatePublicKey(d var deviceVerifyPublicKeyBytes = deviceVerifyPublicKey.Export(X509ContentType.Cert); File.WriteAllBytes($"deviceVerify.cer", deviceVerifyPublicKeyBytes); ``` + +## Exporting Importing PEM + +RSA + +```csharp +var sp = new ServiceCollection() + .AddCertificateManager() + .BuildServiceProvider(); + +var ccRsa = sp.GetService(); +var iec = sp.GetService(); + +var rsaCert = ccRsa.CreateDevelopmentCertificate("localhost", 2, 2048); + +// export +var publicKeyPem = iec.PemExportPublicKeyCertificate(rsaCert); +var rsaPrivateKeyPem = iec.PemExportRsaPrivateKey(rsaCert); + +// import +var roundTripPublicKeyPem = iec.PemImportCertificate(publicKeyPem); +var roundTripRsaPrivateKeyPem = iec.PemImportPrivateKey(rsaPrivateKeyPem); + +var roundTripFullCert = + iec.CreateCertificateWithPrivateKey( + roundTripPublicKeyPem, + roundTripRsaPrivateKeyPem, + "1234"); + +``` + +ECDsa + +```csharp +var sp = new ServiceCollection() + .AddCertificateManager() + .BuildServiceProvider(); + +var cc = serviceProvider.GetService(); + +var root = cc.NewRootCertificate( + new DistinguishedName { CommonName = "root dev", Country = "IT" }, + new ValidityPeriod { ValidFrom = DateTime.UtcNow, ValidTo = DateTime.UtcNow.AddYears(10) }, + 3, "localhost"); +root.FriendlyName = "developement root L1 certificate"; + +var iec = sp.GetService(); + +// export +var publicKeyPem = iec.PemExportPublicKeyCertificate(root); +var eCDsaPrivateKeyPem = iec.PemExportECPrivateKey(root); + +// import +var roundTripPublicKeyPem = iec.PemImportCertificate(publicKeyPem); +var roundTripECPrivateKeyPem = iec.PemImportPrivateKey(eCDsaPrivateKeyPem); + +var roundTripFullCert = + iec.CreateCertificateWithPrivateKey( + roundTripPublicKeyPem, + roundTripECPrivateKeyPem, + "1234"); + +``` ## General Certificates, full APIs ### Self signed certificate