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

Exporting self singed cert

parent 6b60061a
No related branches found
No related tags found
1 merge request!3Feature/440 mvp net sdk part 1
......@@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging;
namespace FitConnect;
public abstract class FunctionalBaseClass : EncryptionBaseClass {
public class FunctionalBaseClass : EncryptionBaseClass {
protected readonly ILogger? logger;
public FitConnectEndpoints Endpoints { get; }
......
using System;
using System.Buffers.Text;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using FitConnect;
using FluentAssertions;
......@@ -21,6 +23,23 @@ public class SenderEncryptionTest {
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development));
}
private X509Certificate2 CreateSelfSignedCertificate() {
var req = new CertificateRequest("cn=foobar", ECDsa.Create(), HashAlgorithmName.SHA256);
var cert = req.CreateSelfSigned(DateTimeOffset.Now, DateTimeOffset.Now.AddYears(5));
// Create PFX (PKCS #12) with private key
File.WriteAllBytes("../../../mycert.pfx", cert.Export(X509ContentType.Pfx, "P@55w0rd"));
// Create Base 64 encoded CER (public key only)
File.WriteAllText("../../../mycert.cer",
"-----BEGIN CERTIFICATE-----\r\n"
+ Convert.ToBase64String(cert.Export(X509ContentType.Cert),
Base64FormattingOptions.InsertLineBreaks)
+ "\r\n-----END CERTIFICATE-----");
return cert;
}
[Test]
public void CryptWithPublicKeyImport() {
var publicKey = Convert.FromBase64String(
......
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