Beispiel #1
0
        private static void ReEncryptFile()
        {
            string      oldAliasName = string.Empty;
            string      newAliasName = string.Empty;
            string      infile       = string.Empty;
            X509Alias   OldAlias     = null;
            X509Alias   NewAlias     = null;
            X509Context OldContext   = null;
            X509Context NewContext   = null;

            try
            {
                oldAliasName = SelectedMode.GetString(Parameter.OldAlias.ID);
                newAliasName = SelectedMode.GetString(Parameter.NewAliasReEnc.ID);
                OldContext   = SelectedMode.GetContext(Parameter.OldContext.ID);
                NewContext   = SelectedMode.GetContext(Parameter.NewContext.ID);
                infile       = SelectedMode.GetString(Parameter.InReEncFile.ID);

                OldAlias = new X509Alias(oldAliasName, OldContext);
                NewAlias = new X509Alias(newAliasName, NewContext);
                X509Utils.ReEncryptFile(OldAlias, NewAlias, infile);

                ConsoleMessage($"The file {infile.InQuotes()} was successfully re-encrypted using the X509Crypto alias {newAliasName.InQuotes()} located in the {NewContext.Name.InQuotes()} {nameof(X509Context)}");
            }
            catch (Exception ex)
            {
                throw new X509CryptoException(@"Unable to re-encrypt the specified file", ex);
            }
        }