XlsCrypt.NativeExcelEncryption
1.1.1
dotnet add package XlsCrypt.NativeExcelEncryption --version 1.1.1
NuGet\Install-Package XlsCrypt.NativeExcelEncryption -Version 1.1.1
<PackageReference Include="XlsCrypt.NativeExcelEncryption" Version="1.1.1" />
<PackageVersion Include="XlsCrypt.NativeExcelEncryption" Version="1.1.1" />
<PackageReference Include="XlsCrypt.NativeExcelEncryption" />
paket add XlsCrypt.NativeExcelEncryption --version 1.1.1
#r "nuget: XlsCrypt.NativeExcelEncryption, 1.1.1"
#:package XlsCrypt.NativeExcelEncryption@1.1.1
#addin nuget:?package=XlsCrypt.NativeExcelEncryption&version=1.1.1
#tool nuget:?package=XlsCrypt.NativeExcelEncryption&version=1.1.1
XlsCrypt.NativeExcelEncryption
Native .NET library for password-based encryption and decryption of Excel .xlsx workbooks.
Features
- Native .NET implementation
- Excel-compatible workbook encryption
- Encrypt and decrypt password-protected
.xlsxfiles - Uses the Office Agile Encryption format
- AES-256-CBC encryption
- SHA-512 hashing
- Password-based key derivation
- HMAC-SHA512 data integrity verification
- No EPPlus dependency
- No ClosedXML dependency
- No Microsoft Office installation required
- Designed for server-side and automated environments
Installation
Install the NuGet package:
dotnet add package XlsCrypt.NativeExcelEncryption
Or using the NuGet Package Manager:
Install-Package XlsCrypt.NativeExcelEncryption
Usage
Encrypt
using XlsxCrypt;
ExcelEncryption.EncryptFile(
"input.xlsx",
"encrypted.xlsx",
"your-password");
Decrypt
using XlsxCrypt;
ExcelEncryption.DecryptFile(
"encrypted.xlsx",
"decrypted.xlsx",
"your-password");
Complete Example
using XlsxCrypt;
string inputFile = @"C:\Excel\input.xlsx";
string encryptedFile = @"C:\Excel\encrypted.xlsx";
string decryptedFile = @"C:\Excel\decrypted.xlsx";
string password = "StrongPassword123!";
// Encrypt unencrypted .xlsx
ExcelEncryption.EncryptFile(
inputFile,
encryptedFile,
password);
// Decrypt password-protected .xlsx
ExcelEncryption.DecryptFile(
encryptedFile,
decryptedFile,
password);
Note:
NativeExcelEncryption.EncryptFileandNativeExcelEncryption.DecryptFileare also available as direct entry points.
How It Works
XlsCrypt uses Microsoft's Office Agile Encryption format to protect .xlsx workbooks.
The workbook package is encrypted using AES-256-CBC with 4096-byte segments. The encrypted package, encryption metadata, and Office DataSpaces information are stored in an OLE Compound File.
The encryption process includes:
- Password-based key derivation
- SHA-512 hashing
- AES-256-CBC encryption
- Random salts
- Password verification
- Encrypted workbook key
- HMAC-SHA512 integrity verification
- Office DataSpaces metadata
EncryptionInfoEncryptedPackage
Decryption reverses this process and verifies the password and encrypted package integrity before producing the original .xlsx workbook.
Why XlsCrypt?
XlsCrypt provides a native .NET approach to Excel workbook encryption without requiring:
- EPPlus
- ClosedXML
- Microsoft Office
- Excel COM automation
This makes it suitable for applications that need to protect Excel workbooks programmatically, particularly server-side and automated workloads.
Compatibility
The library uses the Microsoft Office Agile Encryption format and is intended to produce password-protected .xlsx workbooks compatible with Microsoft Excel.
Always test encrypted workbooks with the Excel versions and environments relevant to your application before using the library in production.
Security
This library implements cryptographic operations required by the Office Agile Encryption format.
The security of an encrypted workbook also depends on the password used to protect it.
Recommendations:
- Use strong, unique passwords.
- Do not hard-code passwords in source code.
- Do not log passwords.
- Store passwords securely.
- Test the library thoroughly before using it for highly sensitive or regulated data.
This project has not been presented as a replacement for a formal security review or cryptographic audit.
Requirements
- .NET 10
- Windows
Release Notes
v1.1.1
- Fixed Office Agile Encryption data integrity HMAC key size for SHA-512 compliance.
- Fixed OLE Compound File DataSpaces structure, alignment, and version metadata streams.
- Added full workbook decryption support (
DecryptFile) with package integrity and password verification.
License
MIT License.
See the LICENSE file for the complete license text.
Repository
Source code and development history are available on GitHub:
https://github.com/pragmasujit/xlsxcrypt
Disclaimer
XlsCrypt.NativeExcelEncryption is an independent open-source project and is not affiliated with, sponsored by, or endorsed by Microsoft Corporation.
Excel and Microsoft Office are trademarks of Microsoft Corporation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|