Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.Cryptography.DefaultSecureMimeContext"/> class.
        /// </summary>
        /// <remarks>
        /// <para>Allows the program to specify its own location for the SQLite database. If the file does not exist,
        /// it will be created and the necessary tables and indexes will be constructed.</para>
        /// <para>Requires linking with Mono.Data.Sqlite.</para>
        /// </remarks>
        /// <param name="fileName">The path to the SQLite database.</param>
        /// <param name="password">The password used for encrypting and decrypting the private keys.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="fileName"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="password"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// The specified file path is empty.
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        /// Mono.Data.Sqlite is not available.
        /// </exception>
        /// <exception cref="System.UnauthorizedAccessException">
        /// The user does not have access to read the specified file.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// An error occurred reading the file.
        /// </exception>
        public DefaultSecureMimeContext(string fileName, string password)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (!SqliteCertificateDatabase.IsAvailable)
            {
                throw new NotSupportedException("Mono.Data.Sqlite is not available.");
            }

            var dir    = Path.GetDirectoryName(fileName);
            var exists = File.Exists(fileName);

            if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            dbase = new SqliteCertificateDatabase(fileName, password);

            if (!exists)
            {
                // TODO: initialize our dbase with some root CA certificates.
            }
        }
Beispiel #2
0
 public SecureMimeContext()
     : base(_database = OpenDatabase("C:\\CodeBase\\EmailEncryption\\certdb.sqlite"))
 {
     CryptographyContext.Register(typeof(SecureMimeContext));
     Import(P12Stream(), "<PWD>"); //Import your own Certificate;
     AddCertificate();
 }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.Cryptography.DefaultSecureMimeContext"/> class.
        /// </summary>
        /// <remarks>
        /// This constructor is useful for supplying a custom <see cref="IX509CertificateDatabase"/>.
        /// </remarks>
        /// <param name="database">The certificate database.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="database"/> is <c>null</c>.
        /// </exception>
        public DefaultSecureMimeContext(IX509CertificateDatabase database)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            dbase = database;
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.Cryptography.DefaultSecureMimeContext"/> class.
		/// </summary>
		/// <remarks>
		/// This constructor is useful for supplying a custom <see cref="IX509CertificateDatabase"/>.
		/// </remarks>
		/// <param name="database">The certificate database.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="database"/> is <c>null</c>.
		/// </exception>
		public DefaultSecureMimeContext (IX509CertificateDatabase database)
		{
			if (database == null)
				throw new ArgumentNullException ("database");

			dbase = database;
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.Cryptography.DefaultSecureMimeContext"/> class.
		/// </summary>
		/// <remarks>
		/// <para>Allows the program to specify its own location for the SQLite database. If the file does not exist,
		/// it will be created and the necessary tables and indexes will be constructed.</para>
		/// <para>Requires linking with Mono.Data.Sqlite.</para>
		/// </remarks>
		/// <param name="fileName">The path to the SQLite database.</param>
		/// <param name="password">The password used for encrypting and decrypting the private keys.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="fileName"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="password"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// The specified file path is empty.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// Mono.Data.Sqlite is not available.
		/// </exception>
		/// <exception cref="System.UnauthorizedAccessException">
		/// The user does not have access to read the specified file.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An error occurred reading the file.
		/// </exception>
		public DefaultSecureMimeContext (string fileName, string password)
		{
			if (fileName == null)
				throw new ArgumentNullException ("fileName");

			if (password == null)
				throw new ArgumentNullException ("password");

			var dir = Path.GetDirectoryName (fileName);
			var exists = File.Exists (fileName);

			if (!string.IsNullOrEmpty (dir) && !Directory.Exists (dir))
				Directory.CreateDirectory (dir);

			if (SqliteCertificateDatabase.IsAvailable)
				dbase = new SqliteCertificateDatabase (fileName, password);
			else
				throw new NotSupportedException ("Mono.Data.Sqlite is not available.");

			if (!exists) {
				// TODO: initialize our dbase with some root CA certificates.
			}
		}