Esempio n. 1
0
        /// <summary>
        /// Creates the self signed certificate and installs into the current users store if
        /// an existing thumbprint does not exist in the configuration file.
        /// Updateds the Add On configuration file with the thumbprint of the generated certificate if one is created.
        /// </summary>
        /// <returns>The thumbprint of the certificate</returns>
        public String CreateSelfSignedCertificate(string baseWorkspace)
        {
            try
            {
                String thumbprint     = GetCertificateInConfigFile();
                var    encryptionCert = GetCertificateWithThumbprint(thumbprint);
                if (thumbprint == null || thumbprint == "none" || encryptionCert == null)
                {
                    certObj.CreateCertificateRequest(Properties.Settings.Default.certName);
                    var selfSignedCert = certObj.InstallCertficate();
                    thumbprint = selfSignedCert.Thumbprint;
                    // Set thumbprint in configuration file.
                    SetCertificateInConfigFile(thumbprint);
                }

                // If the certificate is about to expire, then ask the user if they want to update
                // otherwise continue using existing certificate
                var newThumbprint = updateEncryptionCertificateIfExpiring(baseWorkspace, thumbprint);
                return(newThumbprint);
            }
            catch
            {
                throw;
            }
        }
        private String CreateSelfSignedCertificate(String FriendlyName)
        {
            try
            {
                var certObj = new Certificate();
                certObj.FriendlyName           = FriendlyName;
                certObj.ExpirationLengthInDays = 365;

                certObj.CreateCertificateRequest(FriendlyName);
                var selfSignedCert = certObj.InstallCertficate();
                var thumbprint     = selfSignedCert.Thumbprint;
                return(thumbprint);
            }
            catch
            {
                throw;
            }
        }
 /// <summary>
 /// Creates the self signed certificate and installs into the current users store if
 /// an existing thumbprint does not exist in the configuration file.
 /// Updateds the Add On configuration file with the thumbprint of the generated certificate if one is created.
 /// </summary>
 /// <returns>The thumbprint of the certificate</returns>
 public String CreateSelfSignedCertificate()
 {
     try
     {
         String thumbprint = GetCertificateInConfigFile();
         if (thumbprint == null || thumbprint == "none")
         {
             certObj.CreateCertificateRequest(Properties.Settings.Default.certName);
             var selfSignedCert = certObj.InstallCertficate();
             thumbprint = selfSignedCert.Thumbprint;
             // Set thumbprint in configuration file.
             SetCertificateInConfigFile(thumbprint);
         }
         return(thumbprint);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }