Esempio n. 1
0
 /*
  * tries to encrypt a MimeEntity
  */
 public static MimeEntity EncryptEntity(MimeEntity entity, IEnumerable <MailboxAddress> list)
 {
     using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
     {
         return(ApplicationPkcs7Mime.Encrypt(ctx, list, entity));
     }
 }
Esempio n. 2
0
 /*
  * tries to sign a MimeEntity
  */
 public static MimeEntity SignEntity(MimeEntity entity, MailboxAddress signer)
 {
     using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
     {
         return(MultipartSigned.Create(ctx, signer, DigestAlgorithm.Sha1, entity));
     }
 }
Esempio n. 3
0
 /*
  * returns true if email can be encrypted
  */
 public static string CanEncrypt(Node emails)
 {
     if (emails.Count == 0)
     {
         return("there are no recipients");
     }
     try
     {
         List <MailboxAddress> list = new List <MailboxAddress>();
         foreach (Node idx in emails)
         {
             list.Add(new MailboxAddress("", idx.Get <string>()));
         }
         TextPart entity = new TextPart("text");
         using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
         {
             ApplicationPkcs7Mime.Encrypt(ctx, list, entity);
         }
         return(null);
     }
     catch (Exception err)
     {
         return(err.Message);
     }
 }
Esempio n. 4
0
        /*
         * imports the given certificate file into certificate database
         */
        public static void ImportCertificate(string certificateFile, string password)
        {
            Node getBase = new Node();

            ActiveEvents.Instance.RaiseActiveEvent(
                typeof(CryptographyHelper),
                "magix.file.get-base-path",
                getBase);
            string basePath = getBase["path"].Get <string>();

            using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
            {
                using (FileStream stream = File.OpenRead(basePath + certificateFile))
                {
                    if (!string.IsNullOrEmpty(password))
                    {
                        ctx.Import(stream, password);
                    }
                    else
                    {
                        ctx.Import(stream);
                    }
                }
            }
        }
Esempio n. 5
0
 /*
  * tries to sign and encrypt a MimeEntity
  */
 public static MimeEntity SignAndEncryptEntity(MimeEntity entity, MailboxAddress signer, IEnumerable <MailboxAddress> list)
 {
     using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
     {
         return(ApplicationPkcs7Mime.SignAndEncrypt(ctx, signer, DigestAlgorithm.Sha1, list, entity));
     }
 }
Esempio n. 6
0
 /*
  * returns true if email address can sign email
  */
 public static bool CanSign(string email)
 {
     try
     {
         MailboxAddress signer = new MailboxAddress("", email);
         TextPart       entity = new TextPart("text");
         using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
         {
             MultipartSigned.Create(ctx, signer, DigestAlgorithm.Sha1, entity);
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }