Exemplo n.º 1
0
 protected void ClickToEncrypt_Click(object sender, EventArgs e)
 {
     if (this.FileUpload1.HasFile)
     {
         string fileName = Path.GetFileNameWithoutExtension(this.FileUpload1.PostedFile.FileName);
         string ext      = Path.GetExtension(this.FileUpload1.PostedFile.FileName).ToLower();
         if (ext == ".pptx")
         {
             Stream readFile = this.FileUpload1.PostedFile.InputStream;
             try
             {
                 // Opens the specified presentation
                 IPresentation presentation = Presentation.Open(readFile, txtEnOpen.Text);
                 //Encrypts the presentation
                 presentation.Encrypt(txtEnOpen.Text);
                 //saves the presentation
                 presentation.Save("Encryption.pptx", FormatType.Pptx, Response);
             }
             catch (Exception)
             {
                 this.label1.Text = "Please Check the password";
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Encrypt the word document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void encrypt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(passwordBox1.Password))
                {
                    MessageBox.Show("Please enter password to protect", "Password Missing", MessageBoxButton.OK);
                }
                else
                {
                    //Creates instance for presentation
                    IPresentation presentation = Presentation.Open(textBox1.Tag.ToString(), passwordBox1.Password);
                    //Encrypts the presentation
                    presentation.Encrypt(passwordBox1.Password);
                    //Saving the presentation
                    presentation.Save("Encryption.pptx");
                    //Closing the presentation
                    presentation.Close();

                    if (MessageBox.Show("Do you want to view the encrypted Presentation?", "Encrypted Presentation",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        System.Diagnostics.Process.Start("Encryption.pptx");
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("This file could not be encrypted , please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!",
                                MessageBoxButton.OK);
            }
        }
        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 an encrypt Presentation document
        /// </summary>
        /// <returns>Return the created Presentation document as stream</returns>
        public MemoryStream CreateEncryptPresentation()
        {
            FileStream    fileStreamInput = new FileStream(ResolveApplicationPath(@"syncfusion-presentation.pptx"), FileMode.Open, FileAccess.Read);
            IPresentation presentation    = Syncfusion.Presentation.Presentation.Open(fileStreamInput);

            presentation.Encrypt("syncfusion");
            //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);
            }
        }