XlsxCrypt.NativeExcelEncryption
1.1.2
dotnet add package XlsxCrypt.NativeExcelEncryption --version 1.1.2
NuGet\Install-Package XlsxCrypt.NativeExcelEncryption -Version 1.1.2
<PackageReference Include="XlsxCrypt.NativeExcelEncryption" Version="1.1.2" />
<PackageVersion Include="XlsxCrypt.NativeExcelEncryption" Version="1.1.2" />
<PackageReference Include="XlsxCrypt.NativeExcelEncryption" />
paket add XlsxCrypt.NativeExcelEncryption --version 1.1.2
#r "nuget: XlsxCrypt.NativeExcelEncryption, 1.1.2"
#:package XlsxCrypt.NativeExcelEncryption@1.1.2
#addin nuget:?package=XlsxCrypt.NativeExcelEncryption&version=1.1.2
#tool nuget:?package=XlsxCrypt.NativeExcelEncryption&version=1.1.2
XlsxCrypt.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 XlsxCrypt.NativeExcelEncryption
Or using the NuGet Package Manager:
Install-Package XlsxCrypt.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
XlsxCrypt 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 XlsxCrypt?
XlsxCrypt 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/xlscrypt
Disclaimer
XlsxCrypt.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 | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
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.