NanoXLSX.Writer 3.0.0-rc.3
Loading...
Searching...
No Matches
LegacyPasswordWriter.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2025
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
10using NanoXLSX.Registry;
11using NanoXLSX.Registry.Attributes;
12using NanoXLSX.Utils.Xml;
13using System;
14using System.Collections.Generic;
16
18{
22 [NanoXlsxPlugIn(PlugInUUID = PlugInUUID.PasswordWriter)]
24 {
25 #region properties
26
30 public PasswordType Type { get; private set; }
31
35 public string PasswordHash { get; set; }
36
42 public LegacyPasswordWriter(PasswordType type, string hash)
43 {
44 this.Type = type;
45 this.PasswordHash = hash;
46 }
47
48 #endregion
49 #region constructors
54 {
55 }
56
57 #endregion
58 #region methods
64 public void Init(PasswordType type, string passwordHash)
65 {
66 this.Type = type;
67 this.PasswordHash = passwordHash;
68 }
69
75 public void CopyFrom(IPassword passwordInstance)
76 {
77 throw new NotImplementedException();
78 }
79
84 public bool PasswordIsSet()
85 {
86 return PasswordHash != null;
87 }
88
93 public string GetPassword()
94 {
95 throw new NotImplementedException();
96 }
97
103 public void SetPassword(string plainText)
104 {
105 throw new NotImplementedException();
106 }
107
112 public void UnsetPassword()
113 {
114 throw new NotImplementedException();
115 }
116
121 public IEnumerable<XmlAttribute> GetAttributes()
122 {
123 List<XmlAttribute> attributes = new List<XmlAttribute>();
124 if (Type == PasswordType.WorksheetProtection)
125 {
126 attributes.Add(XmlAttribute.CreateAttribute("password", PasswordHash));
127 }
128 else
129 {
130 attributes.Add(XmlAttribute.CreateAttribute("workbookPassword", PasswordHash));
131 }
132 return attributes;
133 }
134 #endregion
135 }
136}
Static class that contains enums for password handling.
bool PasswordIsSet()
Gets whether a password to write is defined.
void SetPassword(string plainText)
Not relevant for the writer (inherited from IPassword).
string GetPassword()
Not relevant for the writer (inherited from IPassword).
string PasswordHash
Gets or sets the password hash.
void Init(PasswordType type, string passwordHash)
Initializer method with all mandatory parameters.
void UnsetPassword()
Not relevant for the writer (inherited from IPassword).
LegacyPasswordWriter(PasswordType type, string hash)
Default constructor with parameter.
IEnumerable< XmlAttribute > GetAttributes()
Gets the XML attributes of the current password instance, that are used when writing XLSX files.
void CopyFrom(IPassword passwordInstance)
Not relevant for the writer (inherited from IPassword).
PasswordType Type
Current target type of the password instance.
Interface, used by specific writers that provides password handling.