Exemplo 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));
     }
 }
Exemplo 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));
     }
 }
Exemplo 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);
     }
 }
Exemplo 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);
                    }
                }
            }
        }
Exemplo 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));
     }
 }
Exemplo 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);
     }
 }