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