تشفير ملفات Excel
Microsoft Excel (97 - 365) يتيح لك تشفير وحماية كلمة مرور جداول البيانات الخاصة بك. تستخدم خوارزميات المزود الخدمي الكريبتوجرافي، أو CSP، مجموعة من الخوارزميات الكريبتوجرافية ذات خصائص مختلفة. CSP الافتراضي هو ‘Office 97/2000 Compatible’ أو ‘Weak Encryption (XOR)’. من المهم اختيار طول مفتاح التشفير المناسب. بعض CSPs لا تدعم أكثر من 40 أو 56 بت. يعتبر ذلك تشفير ضعيف. للحصول على تشفير قوي، يتطلب طول مفتاح أدنى لـ 128 بت. تحتوي نوافذ Microsoft على CSPs تقدم أنواع تشفير قوية أيضًا، على سبيل المثال ‘مزود تشفير قوي من Microsoft’. لإعطائك فكرة، تشفير 128 بت هو ما تستخدمه البنوك لتشفير الاتصال مع أنظمة الخدمات المصرفية عبر الإنترنت الخاصة بهم.
تسمح Aspose.Cells لك بتشفير وحماية ملفات Microsoft Excel بنوع التشفير الذي ترغب فيه.
استخدام Microsoft Excel
لضبط إعدادات تشفير الملف في Microsoft Excel (هنا Microsoft Excel 2003):
- من قائمة الأدوات، حدد الخيارات. ستظهر نافذة حوارية. ١. حدد علامة التبويب الأمان.
- أدخل كلمة مرور وانقر متقدم ١. اختر نوع التشفير وقم بتأكيد كلمة المرور.
التشفير مع Aspose.Cells
المثال التالي يوضح كيفية تشفير وحماية ملف Excel بكلمة مرور باستخدام واجهة برمجة التطبيقات Aspose.Cells.
// 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.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(dataDir + "encryptedBook1.out.xls"); |
تحديد كلمة المرور لخيار تعديل
المثال التالي يوضح كيفية ضبط خيار Microsoft Excel كلمة المرور للتعديل لملف موجود باستخدام واجهة برمجة التطبيقات Aspose.Cells.
// 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.xls"); | |
// Set the password for modification. | |
workbook.Settings.WriteProtection.Password = "1234"; | |
// Save the excel file. | |
workbook.Save(dataDir + "SpecifyPasswordToModifyOption.out.xls"); |
تحقق من كلمة المرور للملف المُشفر
للتحقق من كلمة المرور للملف المشفر، يوفر Aspose.Cells for .NET الدوال التالية. تقبل هذه الدوال معلمتين، تيار الملف وكلمة المرور التي يجب التحقق منها. يوضح مقتطف الشيفرة التالي استخدام الطريقة VerifyPassword للتحقق مما إذا كانت كلمة المرور المقدمة صالحة أم لا.
// 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); | |
// Create a Stream object | |
FileStream fstream = new FileStream(dataDir + "EncryptedBook1.xlsx", FileMode.Open); | |
bool isPasswordValid = FileFormatUtil.VerifyPassword(fstream, "1234"); | |
Console.WriteLine("Password is Valid: " + isPasswordValid); |
تشفير/فك تشفير ملف ODS بـ Aspose.Cells
يسمح Aspose.Cells بتشفير وفك تشفير ملف ODS. يمكن فتح ملف ODS المفك شفرته في كل من Excel و OpenOffice، ومع ذلك، يمكن فتح ملف ODS المشفر شفرته فقط بواسطة OpenOffice بعد تقديم كلمة المرور. لا يمكن لـ Excel فتح ملف ODS المشفر وقد يثير رسالة تحذير. خيارات التشفير غير مطبقة على ملفات ODS على عكس أنواع الملفات الأخرى. لتشفير ملف ODS، قم بتحميل الملف وضبط WorkbookSettings.Password بنفس كلمة المرور الفعلية قبل حفظه. يمكن فتح ملف ODS المشفر الناتج في OpenOffice فقط.
// 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 sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Open an ODS file | |
Workbook workbook = new Workbook(sourceDir + "sampleODSFile.ods"); | |
// Password protect the file | |
workbook.Settings.Password = "1234"; | |
// Save the ODS file | |
workbook.Save(outputDir + "outputEncryptedODSFile.ods"); |
لفك تشفير ملف ODS، قم بتحميل الملف عن طريق تقديم كلمة مرور في LoadOptions.Password. بمجرد تحميل الملف، ضبط السلسلة WorkbookSettings.Password على القيمة الخالية.
// 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 sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Open an encrypted ODS file | |
Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Ods); | |
// Set original password | |
loadOptions.Password = "1234"; | |
// Load the encrypted ODS file with the appropriate load options | |
Workbook workbook = new Workbook(sourceDir + "sampleEncryptedODSFile.ods", loadOptions); | |
// Set the password to null | |
workbook.Settings.Password = null; | |
// Save the decrypted ODS file | |
workbook.Save(outputDir + "outputDecryptedODSFile.ods"); |