public static CertificateAndKey FromPfx(string path, string password) { var cert = new CertificateAndKey(); cert.LoadPfx(path, password); return(cert); }
public static CertificateAndKey FromPem(string certPath, string keyPath) { var cert = new CertificateAndKey(); cert.LoadPem(certPath, keyPath); return(cert); }
private static CertificateAndKey FromPem(string directory, int?n = null) { string number = n?.ToString() ?? ""; string certPath = Path.Combine(directory, pemCertName + number + ".pem"); string keyPath = Path.Combine(directory, pemPrivkeyName + number + ".pem"); if (!File.Exists(certPath) || !File.Exists(keyPath)) { return(null); } return(CertificateAndKey.FromPem(certPath, keyPath)); }
private void LoadCertificatesPfx(IConfigurationSection section) { archive = new(); string password = section.GetValue <string>("Password") ?? throw new ArgumentNullException("Config: Certificates/Password"); string currentPath = section.GetValue <string>("CurrentPath") ?? throw new ArgumentNullException("Config: Certificates/CurrentPath"); currentCert = CertificateAndKey.FromPfx(currentPath, password); if (section.GetValue <string>("ArchivePath") is string archivePath) { foreach (string certPath in Directory.EnumerateFiles(archivePath)) { archive.Add(CertificateAndKey.FromPfx(certPath, password)); } } }
private void LoadCertificatesPem(IConfigurationSection section) { archive = new(); string currentPath = section.GetValue <string>("CurrentPath") ?? throw new ArgumentNullException("Config: Certificates/CurrentPath"); currentCert = FromPem(currentPath) ?? throw new FileNotFoundException("Current Certificate not found"); if (section.GetValue <string>("ArchivePath") is string archivePath) { for (int i = 1; ; i++) { CertificateAndKey cert = FromPem(archivePath, i); if (cert is null) { break; } archive.Add(cert); } } }