Exemplo n.º 1
0
 public void EncryptedFile()
 {
     using (OfficeCryptoStream s = OfficeCryptoStream.Open("test.xlsx"))
     {
         s.Password = "******";
         s.Save();
     }
 }
Exemplo n.º 2
0
 void ChangePassword(String oldPassword, String newPassword)
 {
     using (OfficeCryptoStream s = OfficeCryptoStream.Open(TestFile, oldPassword))
     {
         s.Password = newPassword;
         s.Save();
     }
 }
Exemplo n.º 3
0
 public static void AccessEncryptedFile()
 {
     using (OfficeCryptoStream stream = OfficeCryptoStream.Open("a.xlsx", "password"))
     {
         DoStuff(stream);
         stream.Save(); // Skip this line if you don't want to save/encrypt
     }
 }
Exemplo n.º 4
0
 public static void AccessPlaintextFile()
 {
     using (OfficeCryptoStream stream = OfficeCryptoStream.Open("a.xlsx"))
     {
         DoStuff(stream);
         stream.Save();
     }
 }
Exemplo n.º 5
0
        void CreateTestWorkbook(String password)
        {
            using (OfficeCryptoStream s = OfficeCryptoStream.Open(TestFile))
            {
                s.Password = password;

                s.Save();
            }
        }
Exemplo n.º 6
0
        public static void AccessEncryptedFileManualSave()
        {
            // Create stream, decrypt
            OfficeCryptoStream stream = OfficeCryptoStream.Open("a.xlsx", "password");

            // Do whatever is needed in your program
            DoStuff(stream);

            // When done, save and close the encrypted stream
            stream.Save();
            stream.Close();
        }
Exemplo n.º 7
0
        public static void CreateEncryptedFile()
        {
            using (OfficeCryptoStream stream = OfficeCryptoStream.Create("a.xlsx"))
            {
                DoStuff(stream);

                // Set or change the password anytime before the save.
                // Set to null to save as plaintext.
                stream.Password = "******";

                stream.Save();
            }
        }
Exemplo n.º 8
0
 void CreateTestWorkbook(String password)
 {
     using (OfficeCryptoStream s = OfficeCryptoStream.Create(TestFile))
     {
         s.Password = password;
         using (ExcelPackage p = new ExcelPackage(s))
         {
             ExcelWorksheet ws = p.Workbook.Worksheets["Test"];
             if (ws == null)
             {
                 ws = p.Workbook.Worksheets.Add("Test");
             }
             ws.Cell(1, 1).Value = "Test Cell";
             p.Save();
         }
         s.Save();
     }
 }