-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCertificateHelper.cs
More file actions
31 lines (25 loc) · 1.02 KB
/
CertificateHelper.cs
File metadata and controls
31 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace NHS.CohortManager.CaasIntegrationService;
using System.Security.Cryptography.X509Certificates;
public static class CertificateHelper
{
public static X509Certificate2Collection GetCertificatesFromString(string certificatesString)
{
X509Certificate2Collection certs = [];
X509Certificate2[] pemCerts = certificatesString
.Split("-----END CERTIFICATE-----", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Select(pem => pem + "\n-----END CERTIFICATE-----")
.Select(pem =>
{
var base64 = pem
.Replace("-----BEGIN CERTIFICATE-----", "")
.Replace("-----END CERTIFICATE-----", "")
.Replace("\n", "")
.Replace("\r", "")
.Trim();
return new X509Certificate2(Convert.FromBase64String(base64));
})
.ToArray();
certs.AddRange(pemCerts);
return certs;
}
}