NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
NanoXLSX.LegacyPassword Class Reference

Class implementing a legacy password, based on the proprietary hashing algorithm of Excel. More...

Inheritance diagram for NanoXLSX.LegacyPassword:

Public Types

enum  PasswordType { WorkbookProtection , WorksheetProtection }
 Target type of the password. More...

Public Member Functions

 LegacyPassword (PasswordType type)
 Default constructor with parameter.
string GetPassword ()
 Gets the pain text password.
void SetPassword (string plainText)
 Sets the current password and calculates the hash.
void UnsetPassword ()
 Removes the password form the current instance.
bool PasswordIsSet ()
 Gets whether a password was set.
void CopyFrom (IPassword passwordInstance)
 Copes all data from another class instance.
override bool Equals (object obj)
 Returns whether two instances are the same.
override int GetHashCode ()
 Gets the hash code of the password instance. Note that this is not the actual password hash.

Static Public Member Functions

static string GenerateLegacyPasswordHash (string password)
 Method to generate a legacy (Excel internal) password hash, to protect workbooks or worksheets
This method is derived from the c++ implementation by Kohei Yoshida (http://kohei.us/2008/01/18/excel-sheet-protection-password-hash/).

Properties

PasswordType Type [get, set]
 Current target type of the password instance.
string PasswordHash [get, set]
 Gets or sets the hashed password.

Detailed Description

Class implementing a legacy password, based on the proprietary hashing algorithm of Excel.

Definition at line 20 of file LegacyPassword.cs.

Member Enumeration Documentation

◆ PasswordType

Target type of the password.

Enumerator
WorkbookProtection 

Password is used to protect a workbook.

WorksheetProtection 

Password is used to protect a worksheet.

Definition at line 25 of file LegacyPassword.cs.

Constructor & Destructor Documentation

◆ LegacyPassword()

NanoXLSX.LegacyPassword.LegacyPassword ( PasswordType type)

Default constructor with parameter.

Parameters
typeCurrent target type of the password instance

Definition at line 54 of file LegacyPassword.cs.

Member Function Documentation

◆ CopyFrom()

void NanoXLSX.LegacyPassword.CopyFrom ( IPassword passwordInstance)

Copes all data from another class instance.

Parameters
passwordInstanceOther instance (source)

Implements NanoXLSX.Interfaces.IPassword.

Definition at line 116 of file LegacyPassword.cs.

◆ Equals()

override bool NanoXLSX.LegacyPassword.Equals ( object obj)

Returns whether two instances are the same.

Parameters
objObject to compare
Returns
True if this instance and the other are the same

Definition at line 200 of file LegacyPassword.cs.

◆ GenerateLegacyPasswordHash()

string NanoXLSX.LegacyPassword.GenerateLegacyPasswordHash ( string password)
static

Method to generate a legacy (Excel internal) password hash, to protect workbooks or worksheets
This method is derived from the c++ implementation by Kohei Yoshida (http://kohei.us/2008/01/18/excel-sheet-protection-password-hash/).

Remarks
WARNING! Do not use this method to encrypt 'real' passwords or data outside from NanoXLSX. This is only a minor security feature. Use a proper cryptography method instead.
Parameters
passwordPassword string in UTF-8 to encrypt. Null or an empty string (even technical valid) are not allowed, since they cannot be inserted in a password field in Excel
Returns
16 bit hash as hex string. If the passed plain text password is null or empty, the returned hash will be empty

Definition at line 132 of file LegacyPassword.cs.

◆ GetHashCode()

override int NanoXLSX.LegacyPassword.GetHashCode ( )

Gets the hash code of the password instance. Note that this is not the actual password hash.

Returns
Hash code of the password instance

Definition at line 213 of file LegacyPassword.cs.

◆ GetPassword()

string NanoXLSX.LegacyPassword.GetPassword ( )

Gets the pain text password.

Returns
Plain text password as string, or null, if not defined

Implements NanoXLSX.Interfaces.IPassword.

Definition at line 64 of file LegacyPassword.cs.

◆ PasswordIsSet()

bool NanoXLSX.LegacyPassword.PasswordIsSet ( )

Gets whether a password was set.

Returns
True if a password was defined, false otherwise

Implements NanoXLSX.Interfaces.IPassword.

Definition at line 107 of file LegacyPassword.cs.

◆ SetPassword()

void NanoXLSX.LegacyPassword.SetPassword ( string plainText)

Sets the current password and calculates the hash.

Parameters
plainTextPlain text password. If null or empty, the password will be unset

Implements NanoXLSX.Interfaces.IPassword.

Definition at line 77 of file LegacyPassword.cs.

◆ UnsetPassword()

void NanoXLSX.LegacyPassword.UnsetPassword ( )

Removes the password form the current instance.

Implements NanoXLSX.Interfaces.IPassword.

Definition at line 94 of file LegacyPassword.cs.

Property Documentation

◆ PasswordHash

string NanoXLSX.LegacyPassword.PasswordHash
getset

Gets or sets the hashed password.

Returns

Implements NanoXLSX.Interfaces.IPassword.

Definition at line 48 of file LegacyPassword.cs.

◆ Type

PasswordType NanoXLSX.LegacyPassword.Type
getset

Current target type of the password instance.

Definition at line 42 of file LegacyPassword.cs.


The documentation for this class was generated from the following file: