Ejemplo n.º 1
0
 protected void ClickToDecrypt_Click(object sender, EventArgs e)
 {
     if (this.FileUpload2.HasFile)
     {
         string fileName = Path.GetFileNameWithoutExtension(this.FileUpload2.PostedFile.FileName);
         string ext      = Path.GetExtension(this.FileUpload2.PostedFile.FileName).ToLower();
         if (ext == ".pptx")
         {
             Stream readFile = this.FileUpload2.PostedFile.InputStream;
             try
             {
                 //Opens the specified file
                 IPresentation presentation = Presentation.Open(readFile, txtDeOpen.Text);
                 //Decrypts the document
                 presentation.RemoveEncryption();
                 //Saving the presentation
                 presentation.Save("Decryption.pptx", FormatType.Pptx, Response);
             }
             catch (Exception)
             {
                 this.label1.Text = "Please check the password";
             }
         }
     }
 }
        public ActionResult EncryptAndDecrypt(string Group1, string Group2)
        {
            string     basePath        = _hostingEnvironment.WebRootPath;
            FileStream fileStreamInput = new FileStream(basePath + @"/Presentation/Syncfusion Presentation.pptx", FileMode.Open, FileAccess.Read);

            if (Group1 == "CreateEncryptDoc")
            {
                IPresentation presentation = Presentation.Open(fileStreamInput);
                presentation.Encrypt("syncfusion");
                MemoryStream ms = new MemoryStream();
                //Saves the presentation to the memory stream.
                presentation.Save(ms);
                //Set the position of the stream to beginning.
                ms.Position = 0;
                return(File(ms, "application/vnd.openxmlformats-officedocument.presentationml.presentation", "Encryption.pptx"));
            }
            else
            {
                IPresentation presentation = Presentation.Open(fileStreamInput);
                presentation.RemoveEncryption();
                MemoryStream ms = new MemoryStream();
                //Saves the presentation to the memory stream.
                presentation.Save(ms);
                //Set the position of the stream to beginning.
                ms.Position = 0;
                //Initialize the file stream to download the presentation.
                FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.presentationml.presentation");
                //Set the file name.
                fileStreamResult.FileDownloadName = "Decryption.pptx";
                return(fileStreamResult);
            }
        }
        /// <summary>
        /// Encrypts and decrypts the presentation.
        /// </summary>
        private void BtnCreatePresn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            string fileName;
            //Gets the input PowerPoint Presentation file.
            Assembly assembly     = typeof(EncryptAndDecrypt).GetTypeInfo().Assembly;
            string   resourcePath = "syncfusion.presentationdemos.winui.Assets.Presentation.SyncfusionPresentation.pptx";

            using Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
            //Opens an existing PowerPoint Presentation file.
            using IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream);
            using MemoryStream ms            = new();
            if (rdEncrypt.IsChecked == true)
            {
                //Encrypts the PowerPoint Presentation file.
                presentation.Encrypt("syncfusion");
                fileName = "Encrypt.pptx";
            }
            else
            {
                //Decrypts the PowerPoint Presentation file.
                presentation.RemoveEncryption();
                fileName = "Decrypt.pptx";
            }
            //Saves the presentation to the memory stream.
            presentation.Save(ms);
            ms.Position = 0;
            //Saves the memory stream as file.
            SaveAndLaunch.Save(fileName, ms);
        }
        /// <summary>
        /// Create a decrypt Presentation document
        /// </summary>
        /// <returns>Return the created Presentation document as stream</returns>
        public MemoryStream CreateDecryptPresentation()
        {
            FileStream    fileStreamInput = new FileStream(ResolveApplicationPath(@"syncfusion-presentation.pptx"), FileMode.Open, FileAccess.Read);
            IPresentation presentation    = Syncfusion.Presentation.Presentation.Open(fileStreamInput);

            presentation.RemoveEncryption();
            //Save the document as a stream and retrun the stream
            using (MemoryStream stream = new MemoryStream())
            {
                //Save the created PowerPoint document to MemoryStream
                presentation.Save(stream);
                return(stream);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Decrypt the word document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void decrpt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (textBox2.Tag == null)
                {
                    MessageBox.Show("Please browse the Presentation to decrypt", "Input Missing", MessageBoxButton.OK);
                }
                else if (string.IsNullOrEmpty(passwordBox2.Password))
                {
                    MessageBox.Show("Please enter password to decrypt", "Password Missing", MessageBoxButton.OK);
                }
                else
                {
                    //creates instance for the presentation
                    IPresentation presentation = Presentation.Open(textBox2.Tag.ToString(), passwordBox2.Password);
                    //Decrypts the presentation
                    presentation.RemoveEncryption();
                    //Saving the presentation
                    presentation.Save("Decryption.pptx");
                    //Closing the document
                    presentation.Close();

                    if (MessageBox.Show("Do you want to view the decrypted Presentation?", "Decrypted Presentation",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
#if !NETCore
                        System.Diagnostics.Process.Start("Decryption.pptx");
#else
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Decryption.pptx")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#endif
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("Please enter correct password", "Incorrect password",
                                MessageBoxButton.OK);
            }
        }