Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active May 31, 2021 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/f90033ab91c802a44d474aa181e4f5b4 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/f90033ab91c802a44d474aa181e4f5b4 to your computer and use it in GitHub Desktop.
// 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");
// 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");
// 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);
@aspose-com-gists
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment