// (c) 2006 Richard Grimes // www.grimes.demon.co.uk using System; using System.Security.Cryptography.Pkcs; using System.Security.Cryptography.X509Certificates; using System.IO; using System.Text; class App { // Command line params: e|d infile outfile [certname] static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: envelope e|d infile outfile [certname]"); return; } bool encrypt = true; encrypt = (args[0].ToLower()[0] == 'e'); string infile = args[1]; if (!File.Exists(infile)) { Console.WriteLine("{0} does not exist", infile); return; } string outfile = args[2]; if (File.Exists(outfile)) { File.Delete(outfile); } if (encrypt) { string certname = args[3]; X509Certificate2 cert = GetCertificate(certname); if (cert == null) { Console.WriteLine("No certificate with the name {0}", certname); return; } EncryptMsg(infile, outfile, cert); } else { DecryptMsg(infile, outfile); } } static X509Certificate2 GetCertificate(string certname) { X509Store store = new X509Store(StoreName.AddressBook, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly); X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectName, certname, false); store.Close(); if (certs.Count == 0) return null; return certs[0]; } static void EncryptMsg(string infile, string outfile, X509Certificate2 cert) { } static void DecryptMsg(string infile, string outfile) { } }