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 diff --git a/Documentation.md b/Documentation.md index 43944bc..711ee7d 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: @@ -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 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