Last active
April 14, 2021 10:00
-
-
Save ankitvijay/2cce84b77c6692e4ee8b9b943aeda9e8 to your computer and use it in GitHub Desktop.
Azure App Service: Load certifcate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Security.Cryptography.X509Certificates; | |
public static class CertificateExtensions | |
{ | |
// Private certificatePath: $"/var/ssl/private/{thumbprint}.p12" | |
// Public certificatePath: $"/var/ssl/certs/{thumbprint}.der" | |
public static X509Certificate2 LoadCertificate(string thumbprint, string certificatePath) | |
{ | |
if (string.IsNullOrWhiteSpace(thumbprint)) | |
{ | |
throw new ArgumentNullException(nameof(thumbprint)); | |
} | |
if (string.IsNullOrWhiteSpace(certificatePath)) | |
{ | |
throw new ArgumentNullException(nameof(certificatePath)); | |
} | |
var bytes = File.ReadAllBytes(certificatePath); | |
var certificate = new X509Certificate2(bytes); | |
return certificate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment