Created
March 5, 2019 13:08
-
-
Save gabrielbarceloscn/d4eafa0e7edaad7adf3f69ec731da14e to your computer and use it in GitHub Desktop.
Find and load a X509Certificate2 as an embedded resource as a file in c#
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
var assembly = Assembly.GetEntryAssembly(); | |
var resourceName = "ravencrt1.pfx2"; | |
var resourcePath = assembly.GetName().Name + "." + resourceName.Replace(" ", "_") | |
.Replace("\\", ".") | |
.Replace("/", "."); | |
using (var resourceStream = assembly.GetManifestResourceStream(resourcePath)) | |
{ | |
if (resourceStream != null) | |
{ | |
byte[] ba = new byte[resourceStream.Length]; | |
resourceStream.Read(ba, 0, ba.Length); | |
certificate = new X509Certificate2(ba); | |
} | |
} | |
if (certificate == null) | |
throw new Exception("Não foram encontrados certificados cliente para o servidor."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment