1 | /*******************************************************************************
|
---|
2 | * You may amend and distribute as you like, but don't remove this header!
|
---|
3 | *
|
---|
4 | * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
|
---|
5 | * See http://www.codeplex.com/EPPlus for details.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2011 Jan Källman
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | * See the GNU Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
|
---|
20 | * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
|
---|
21 | *
|
---|
22 | * All code and executables are provided "as is" with no warranty either express or implied.
|
---|
23 | * The author accepts no liability for any damage or loss of business that this product may cause.
|
---|
24 | *
|
---|
25 | * Code change notes:
|
---|
26 | *
|
---|
27 | ***************************************************************************************
|
---|
28 | * This class is created with the help of the MS-OFFCRYPTO PDF documentation... http://msdn.microsoft.com/en-us/library/cc313071(office.12).aspx
|
---|
29 | * Decrypytion library for Office Open XML files(Lyquidity) and Sminks very nice example
|
---|
30 | * on "Reading compound documents in c#" on Stackoverflow. Many thanks!
|
---|
31 | ***************************************************************************************
|
---|
32 | *
|
---|
33 | * Code change notes:
|
---|
34 | *
|
---|
35 | * Author Change Date
|
---|
36 | *******************************************************************************
|
---|
37 | * Jan Källman Added 10-AUG-2010
|
---|
38 | * Jan Källman License changed GPL-->LGPL 2011-12-27
|
---|
39 | *******************************************************************************/
|
---|
40 | using System;
|
---|
41 | using System.Collections.Generic;
|
---|
42 | using System.Text;
|
---|
43 |
|
---|
44 | namespace OfficeOpenXml
|
---|
45 | {
|
---|
46 | /// <summary>
|
---|
47 | /// Encryption Algorithm
|
---|
48 | /// </summary>
|
---|
49 | public enum EncryptionAlgorithm
|
---|
50 | {
|
---|
51 | /// <summary>
|
---|
52 | /// 128-bit AES. Default
|
---|
53 | /// </summary>
|
---|
54 | AES128,
|
---|
55 | /// <summary>
|
---|
56 | /// 192-bit AES.
|
---|
57 | /// </summary>
|
---|
58 | AES192,
|
---|
59 | /// <summary>
|
---|
60 | /// 256-bit AES.
|
---|
61 | /// </summary>
|
---|
62 | AES256
|
---|
63 | }
|
---|
64 | /// <summary>
|
---|
65 | /// How and if the workbook is encrypted
|
---|
66 | ///<seealso cref="ExcelProtection"/>
|
---|
67 | ///<seealso cref="ExcelSheetProtection"/>
|
---|
68 | /// </summary>
|
---|
69 | public class ExcelEncryption
|
---|
70 | {
|
---|
71 | /// <summary>
|
---|
72 | /// Constructor
|
---|
73 | /// </summary>
|
---|
74 | internal ExcelEncryption()
|
---|
75 | {
|
---|
76 | Algorithm = EncryptionAlgorithm.AES128;
|
---|
77 | }
|
---|
78 | /// <summary>
|
---|
79 | /// Constructor
|
---|
80 | /// </summary>
|
---|
81 | /// <param name="encryptionAlgorithm">Algorithm used to encrypt the package. Default is AES128</param>
|
---|
82 | internal ExcelEncryption(EncryptionAlgorithm encryptionAlgorithm)
|
---|
83 | {
|
---|
84 | Algorithm = encryptionAlgorithm;
|
---|
85 | }
|
---|
86 | bool _isEncrypted = false;
|
---|
87 | /// <summary>
|
---|
88 | /// Is the package encrypted
|
---|
89 | /// </summary>
|
---|
90 | public bool IsEncrypted
|
---|
91 | {
|
---|
92 | get
|
---|
93 | {
|
---|
94 | return _isEncrypted;
|
---|
95 | }
|
---|
96 | set
|
---|
97 | {
|
---|
98 | _isEncrypted = value;
|
---|
99 | if (_isEncrypted)
|
---|
100 | {
|
---|
101 | if (_password == null) _password = "";
|
---|
102 | }
|
---|
103 | else
|
---|
104 | {
|
---|
105 | _password = null;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | string _password=null;
|
---|
110 | /// <summary>
|
---|
111 | /// The password used to encrypt the workbook.
|
---|
112 | /// </summary>
|
---|
113 | public string Password
|
---|
114 | {
|
---|
115 | get
|
---|
116 | {
|
---|
117 | return _password;
|
---|
118 | }
|
---|
119 | set
|
---|
120 | {
|
---|
121 | _password = value;
|
---|
122 | _isEncrypted = (value != null);
|
---|
123 | }
|
---|
124 | }
|
---|
125 | /// <summary>
|
---|
126 | /// Algorithm used for encrypting the package. Default is AES 128-bit
|
---|
127 | /// </summary>
|
---|
128 | public EncryptionAlgorithm Algorithm { get; set; }
|
---|
129 | }
|
---|
130 | }
|
---|