Beispiel #1
0
        static void Main(string[] args)
        {
            var OldAlias = new X509Alias(@"exporttest", X509Context.UserFull);
            var NewAlias = new X509Alias(@"updateSample", X509Context.UserFull);

            OldAlias.EncryptFile(@"P:\_temp\test.docx", @"P:\_temp\test.docx.ctx");
            NewAlias.ReEncryptFile(@"P:\_temp\test.docx.ctx", OldAlias);
        }
Beispiel #2
0
        private static void EncryptFile()
        {
            int         wipeTimesToWrite  = 0;
            string      inFile            = string.Empty;
            string      outfile           = string.Empty;
            string      aliasName         = string.Empty;
            bool        overwriteExisting = false;
            X509Context Context           = null;

            try
            {
                inFile = SelectedMode.GetString(Parameter.InEncFile.ID);
                if (Parameter.OutEncFile.IsDefined)
                {
                    outfile = SelectedMode.GetString(Parameter.OutEncFile.ID);
                }
                else
                {
                    outfile = $"{inFile}{FileExtensions.Ciphertext}";
                }

                overwriteExisting = SelectedMode.GetBool(Parameter.OverWriteExistingFile.ID);
                Util.CheckForExistingFile(outfile, overwriteExisting, Parameter.OverWriteExistingFile.Name, Constants.Affirm);

                if (Parameter.Wipe.IsDefined)
                {
                    if (!Util.WarnConfirm($"You have included the {Parameter.Wipe.Name.InQuotes()} argument. This will permanently delete the file {inFile.InQuotes()} from disk.", Constants.Affirm))
                    {
                        return;
                    }
                    else
                    {
                        wipeTimesToWrite = SelectedMode.GetInt(Parameter.Wipe.ID);
                    }
                }

                aliasName = SelectedMode.GetString(Parameter.AliasEnc.ID);
                Context   = SelectedMode.GetContext(Parameter.Context.ID);
                using (X509Alias Alias = new X509Alias(aliasName, Context))
                {
                    Alias.EncryptFile(inFile, outfile, wipeTimesToWrite);
                }
                StringBuilder Expression = new StringBuilder($"The file {inFile.InQuotes()} was successfully encrypted. The ciphertext file name is {outfile.InQuotes()}");
                if (Parameter.Wipe.IsDefined)
                {
                    Expression.Append($"\r\nThe plaintext file has also been erased from disk");
                }
                ConsoleMessage(Expression.ToString());
            }
            catch (Exception ex)
            {
                throw new X509CryptoException(@"Unable to encrypt the specified file", ex);
            }
        }