예제 #1
0
        private static void ImportAlias()
        {
            try
            {
                string      aliasName         = Parameter.AliasToImport.IsDefined ? SelectedMode.GetString(Parameter.AliasToImport.ID) : string.Empty;
                string      inFile            = SelectedMode.GetString(Parameter.InImportAlias.ID);
                bool        overwriteExisting = SelectedMode.GetBool(Parameter.OverWriteExistingAlias.ID);
                X509Context Context           = SelectedMode.GetContext(Parameter.Context.ID);

                X509Alias AliasToImport = X509Alias.Import(inFile, Context, aliasName);
                if (!overwriteExisting && X509Alias.AliasExists(AliasToImport))
                {
                    throw new X509AliasAlreadyExistsException(AliasToImport);
                }
                AliasToImport.Commit();
                ConsoleMessage($"{nameof(X509Alias)} {AliasToImport.Name.InQuotes()} has been successfully imported into the {Context.Name} {nameof(X509Context)} from the file {inFile.InQuotes()}");

                if (!X509CryptoAgent.CertificateExists(AliasToImport))
                {
                    ConsoleWarning($"An encryption certificate with thumbprint {AliasToImport.Thumbprint.InQuotes()} could not be found in the {Context.Name} {nameof(X509Context)}. Ensure this certificate is installed on the system before using this alias.");
                }
            }
            catch (Exception ex)
            {
                if (ex is X509AliasAlreadyExistsException)
                {
                    throw;
                }
                else
                {
                    throw new X509CryptoException(@"Unable to import the specified alias", ex);
                }
            }
        }
예제 #2
0
        private static void UpdateAlias()
        {
            try
            {
                string      aliasName     = SelectedMode.GetString(Parameter.AliasToUpdate.ID);
                string      newThumbprint = SelectedMode.GetString(Parameter.Thumbprint.ID);
                X509Context OldContext    = SelectedMode.GetContext(Parameter.OldContext.ID);
                X509Context NewContext    = SelectedMode.GetContext(Parameter.NewContext.ID, OldContext);

                if (!X509CryptoAgent.CertificateExists(newThumbprint, NewContext))
                {
                    throw new X509CryptoCertificateNotFoundException(newThumbprint, NewContext);
                }

                X509Alias Alias = new X509Alias(aliasName, OldContext);
                Alias.ReEncrypt(newThumbprint, NewContext);
                Alias.Commit();
                ConsoleMessage($"{nameof(X509Alias)} {aliasName} successfully updated. Now using encryption certificate with thumbprint {newThumbprint} from the {NewContext.Name} {nameof(X509Context)}");
            }
            catch (Exception ex)
            {
                if (ex is X509CryptoCertificateNotFoundException)
                {
                    throw;
                }
                else
                {
                    throw new X509CryptoException(@"Unable to update the specified alias", ex);
                }
            }
        }
예제 #3
0
        private void DoWork()
        {
            var Context       = X509Context.Select(Location, true);
            var AliasToImport = X509Alias.Import(Path, Context, Name);

            if (!Overwrite && X509Alias.AliasExists(AliasToImport))
            {
                throw new X509AliasAlreadyExistsException(AliasToImport);
            }
            AliasToImport.Commit();

            Util.ConsoleMessage($"{nameof(X509Alias)} {AliasToImport.Name.InQuotes()} has been successfully imported into the {Context.Name} {nameof(X509Context)} from the file {Path.InQuotes()}");

            if (!X509CryptoAgent.CertificateExists(AliasToImport))
            {
                Util.ConsoleWarning($"An encryption certificate with thumbprint {AliasToImport.Thumbprint.InQuotes()} could not be found in the {Context.Name} {nameof(X509Context)}. Ensure this certificate is installed on the system before using this alias.");
            }

            Result = AliasToImport;
        }
예제 #4
0
        private void DoWork()
        {
            X509Context OldContext,
                        NewContext;

            OldContext = Alias.Context;
            if (contextSet)
            {
                NewContext = X509Context.Select(Location, false);
            }
            else
            {
                NewContext = Alias.Context;
            }

            if (!X509CryptoAgent.CertificateExists(Thumbprint, NewContext))
            {
                throw new X509CryptoCertificateNotFoundException(Thumbprint, NewContext);
            }
            Alias.ReEncrypt(Thumbprint, NewContext);
            Alias.Commit();
            Console.WriteLine($"{nameof(X509Alias)} {Alias.Name} successfully updated. Now using encryption certificate with thumbprint {Thumbprint} from the {NewContext.Name} {nameof(X509Context)}");
        }