Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Last active April 14, 2021 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankitvijay/2cce84b77c6692e4ee8b9b943aeda9e8 to your computer and use it in GitHub Desktop.
Save ankitvijay/2cce84b77c6692e4ee8b9b943aeda9e8 to your computer and use it in GitHub Desktop.
Azure App Service: Load certifcate
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