Initial commit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user