Last active
May 31, 2021 12:18
-
-
Save aspose-com-gists/f90033ab91c802a44d474aa181e4f5b4 to your computer and use it in GitHub Desktop.
Encrypt and Decrypt Excel Files in C# | https://blog.aspose.com/2021/01/14/encrypt-and-decrypt-excel-files-using-csharp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open an excel file | |
Workbook workbook = new Workbook("encryptedBook.xlsx", new LoadOptions { Password="1234" }); | |
// Set the password to null | |
workbook.Settings.Password = null; | |
// Save the excel file. | |
workbook.Save("decryptedBook.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open an excel file | |
Workbook workbook = new Workbook("Book1.xls"); | |
// Specify XOR encryption type | |
workbook.SetEncryptionOptions(EncryptionType.XOR, 40); | |
// Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider) | |
workbook.SetEncryptionOptions(EncryptionType.StrongCryptographicProvider, 128); | |
// Password protect the file | |
workbook.Settings.Password = "1234"; | |
// Save the excel file | |
workbook.Save("encryptedBook.xls"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a Stream object | |
FileStream fstream = new FileStream("EncryptedBook1.xlsx", FileMode.Open); | |
// Verify password | |
bool isPasswordValid = FileFormatUtil.VerifyPassword(fstream, "1234"); | |
// Print results | |
Console.WriteLine("Password is Valid: " + isPasswordValid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the complete article: https://blog.aspose.com/2021/01/14/encrypt-and-decrypt-excel-files-using-csharp/