Example #1
0
        // try create X509Certificate2 object
        internal static System.Security.Cryptography.X509Certificates.X509Certificate2 TryCreateCertificate(
            KeyFile keyFile, out System.Exception exception)
        {
            exception = null;

            try
            {
                byte[] pfxData;

                // read .pfx
                using (FileStream fs = File.OpenRead(keyFile.FilePath))
                {
                    if (fs.Length == 0)
                    {
                        throw new System.Exception("The key file is empty.");
                    }
                    pfxData = new byte[fs.Length];
                    fs.Read(pfxData, 0, Convert.ToInt32(fs.Length));
                    fs.Close();
                }

                // create certificate
                return(new System.Security.Cryptography.X509Certificates.X509Certificate2(
                           pfxData, keyFile.PfxPassword, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable));
            }
            catch (System.Exception ex)
            {
                exception = ex;
                return(null);
            }
        }
Example #2
0
 private void Reset()
 {
     try
     {
         _ctrVersion1.Text          = "0";
         _ctrVersion2.Text          = "0";
         _ctrVersion3.Text          = "0";
         _ctrVersion4.Text          = "0";
         _ctrFileVersion1.Text      = "0";
         _ctrFileVersion2.Text      = "0";
         _ctrFileVersion3.Text      = "0";
         _ctrFileVersion4.Text      = "0";
         _checkSignAssembly.Checked = false;
         _checkDelaySigning.Checked = false;
         _ctrKeyFile.Text           = "No key file selected";
         _ctrKeyFilePassword.Text   = null;
         _keyFile = new KeyFile();
         _ctrAssemblyVersionMessage.Visible = false;
         _ctrFileVersionMessage.Visible     = false;
         HandleSignAssemblyControl();
     }
     catch (System.Exception ex)
     {
         Common.ShowUnknownException(ex);
     }
 }
Example #3
0
        private void Init()
        {
            // assembly version
            var assemblyVersion = _mappingUI.AssemblyVersion;

            if (assemblyVersion == null)
            {
                assemblyVersion = Tuple.Create(0, 0, 0, 0);
            }
            _ctrVersion1.Text = assemblyVersion.Item1.ToString();
            _ctrVersion2.Text = assemblyVersion.Item2.ToString();
            _ctrVersion3.Text = assemblyVersion.Item3.ToString();
            _ctrVersion4.Text = assemblyVersion.Item4.ToString();

            // file version
            var fileVersion = _mappingUI.FileVersion;

            if (fileVersion == null)
            {
                fileVersion = Tuple.Create(0, 0, 0, 0);
            }
            _ctrFileVersion1.Text = fileVersion.Item1.ToString();
            _ctrFileVersion2.Text = fileVersion.Item2.ToString();
            _ctrFileVersion3.Text = fileVersion.Item3.ToString();
            _ctrFileVersion4.Text = fileVersion.Item4.ToString();

            // key file
            if (_mappingUI.KeyFile != null)
            {
                _keyFile = _mappingUI.KeyFile;
                _checkSignAssembly.Checked = true;
                _ctrKeyFile.Text           = System.IO.Path.GetFileName(_mappingUI.KeyFile.FilePath);
                _ctrKeyFilePassword.Text   = _keyFile.PfxPassword;
                _checkDelaySigning.Checked = _keyFile.IsDelaySigning;
                HandleSignAssemblyControl();
            }

            // tooltips
            _reset.SetToolTip("Reset", "Reset the assembly settings");
            _ctrKeyFile.SetToolTip("Strong name key file", "Choose a string name key file (.snk, .pfx) to sign the mapper assembly", 10);
            _btnAutoAssemblyVersion.SetToolTip("Auto", "Auto set the assembly version number based on the date and time\r\n" +
                                               "passed from 1 Jan, 2000.", 10);
            _btnAutoFileVersion.SetToolTip("Auto", "Auto set the file version number based on the date and time\r\n" +
                                           "passed from 1 Jan, 2000.", 10);
        }