Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.IO;
using System.Security.Cryptography.X509Certificates;
namespace CertificateFoo
{
class Program
{
static void Main(string[] args)
{
using (var certificateStream = GetEmbeddedResourceStream<Program>("foo.p12"))
using (var memoryStream = new MemoryStream())
{
certificateStream.CopyTo(memoryStream);
var certificate = new X509Certificate2(memoryStream.ToArray(),
"passphrase", X509KeyStorageFlags.Exportable);
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
store.Add(certificate);
store.Close();
}
}
private static Stream GetEmbeddedResourceStream<T>(string resourceName)
{
var type = typeof(T);
var assembly = type.Assembly;
return assembly.GetManifestResourceStream(type, resourceName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.