Initial commit

This commit is contained in:
2026-07-13 09:25:40 +07:00
parent c08ff54676
commit bccfb156d7
1938 changed files with 641646 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
using MQTTnet;
using System.Security.Cryptography.X509Certificates;
namespace RobotNet10.MqttConnection;
public class MQTTClientCertificatesProvider(string? CerPath, string? KeyPath) : IMqttClientCertificatesProvider
{
public X509CertificateCollection? GetCertificates()
{
if (!string.IsNullOrEmpty(CerPath) && !string.IsNullOrEmpty(KeyPath))
{
if (File.Exists(CerPath) && File.Exists(KeyPath))
{
var cert = X509Certificate2.CreateFromPem(File.ReadAllText(CerPath), File.ReadAllText(KeyPath));
var pfxBytes = cert.Export(X509ContentType.Pfx);
var pfxCert = X509CertificateLoader.LoadPkcs12(pfxBytes, "", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
return [pfxCert];
}
}
return null;
}
}