NanoXLSX.Writer 3.0.0-rc.5
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 © 2026
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
8using NanoXLSX.Interfaces;
9using NanoXLSX.Interfaces.Writer;
10using NanoXLSX.Registry;
11using NanoXLSX.Registry.Attributes;
12using NanoXLSX.Utils.Xml;
13using System;
14using System.Collections.Generic;
15using static NanoXLSX.Enums.Password;
16
17
19{
23 [NanoXlsxPlugIn(PlugInUUID = PlugInUUID.PasswordWriter)]
24 public class LegacyPasswordWriter : IPasswordWriter
25 {
26 #region properties
27
31 public PasswordType Type { get; private set; }
32
36 public string PasswordHash { get; set; }
37
43 public LegacyPasswordWriter(PasswordType type, string hash)
44 {
45 this.Type = type;
46 this.PasswordHash = hash;
47 }
48
49 #endregion
50 #region constructors
55 {
56 }
57
58 #endregion
59 #region methods
65 public void Init(PasswordType type, string passwordHash)
66 {
67 this.Type = type;
68 this.PasswordHash = passwordHash;
69 }
70
76 public void CopyFrom(IPassword passwordInstance)
77 {
78 throw new NotImplementedException();
79 }
80
85 public bool PasswordIsSet()
86 {
87 return PasswordHash != null;
88 }
89
94 public string GetPassword()
95 {
96 throw new NotImplementedException();
97 }
98
104 public void SetPassword(string plainText)
105 {
106 throw new NotImplementedException();
107 }
108
113 public void UnsetPassword()
114 {
115 throw new NotImplementedException();
116 }
117
122 public IEnumerable<XmlAttribute> GetAttributes()
123 {
124 List<XmlAttribute> attributes = new List<XmlAttribute>();
125 if (Type == PasswordType.WorksheetProtection)
126 {
127 attributes.Add(XmlAttribute.CreateAttribute("password", PasswordHash));
128 }
129 else
130 {
131 attributes.Add(XmlAttribute.CreateAttribute("workbookPassword", PasswordHash));
132 }
133 return attributes;
134 }
135 #endregion
136 }
137}
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.