Skip to content

Instantly share code, notes, and snippets.

@jonman364
Created November 4, 2014 14:35
Show Gist options
  • Save jonman364/88f1fe45780c77045a89 to your computer and use it in GitHub Desktop.
Save jonman364/88f1fe45780c77045a89 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography.X509Certificates;
namespace certreg {
class Program {
static void Main(string[] args) {
if(args.Length == 0) {
Console.WriteLine("Useage:\n\tcertreg path");
return;
}
if(!Directory.Exists(args[0])) {
Console.WriteLine("Cannot open \"" + args[0] + "\"");
return;
}
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
foreach(string filePath in Directory.EnumerateFiles(args[0], "*.pfx")) {
string password = Path.GetFileNameWithoutExtension(filePath); // Where cert password = filename
X509Certificate2 cert = new X509Certificate2(filePath, password);
store.Add(cert);
Console.WriteLine(password);
}
store.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment