设置强加密类型
Contents
[
Hide
]
Microsoft Excel (97-2007/2010) 使您能够加密和密码保护电子表格。它使用加密服务提供商提供的算法。加密服务提供商(或 CSP)是一组具有不同属性的加密算法。默认 CSP 是“Office 97/2000 兼容”。这是一个具有一些众所周知的安全问题的 CSP。使用“弱加密 (XOR)”或“Office 97/2000 兼容”加密类型保护的电子表格很容易被破解。
要解决此问题,请使用 Microsoft Excel 提供的一种强加密类型。您可以将加密类型更改为最强的可用 CSP。对于强加密,需要至少 128 位的密钥长度,例如,“Microsoft Strong Cryptographic Provider”。
您还可以使用 Aspose.Cells API 加密和密码保护具有强加密类型的 Excel 文件。
使用 Microsoft Excel 应用加密
在Microsoft Excel(以2007为例)中实现文件加密:
- 来自工具菜单,选择选项.
- 选择安全标签。
- 输入一个值打开密码场地。
- 点击先进的.
- 选择加密类型并确认密码。
使用 Aspose.Cells 应用加密
下面的代码示例对文件应用强加密并设置密码。
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a Workbook object. | |
// Open an excel file. | |
Workbook workbook = new Workbook(dataDir+ "Book1.xlsx"); | |
// 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(dataDir+ "encryptedBook1.out.xls"); |