Excel Dosyalarını Şifreleme
Microsoft Excel (97 - 365), elektronik tablolarınızı şifrelemeye ve parola koruması yapmaya olanak tanır. Bir şifreleme hizmet sağlayıcısı tarafından sağlanan algoritmalar, yani bir dizi farklı özelliklere sahip şifreleme algoritmaları kullanır. Varsayılan CSP ‘Ofis 97/2000 Uyumlu’ veya ‘Zayıf Şifreleme (XOR)’ dur. Doğru şifreleme anahtar uzunluğunu seçmek önemlidir. Bazı CSP’ler 40 veya 56 bit’ten fazlasını desteklemez. Bu zayıf şifreleme olarak kabul edilir. Güçlü şifreleme için minimum 128 bitlik bir anahtar uzunluğu gereklidir. Microsoft Windows, örneğin ‘Microsoft Güçlü Kriptografik Sağlayıcısı’ gibi güçlü şifreleme türleri sunan CSP’ler içerir. Size bir fikir vermek gerekirse, 128 bitlik şifreleme, bankaların İnternet Bankacılığı sistemleriyle olan bağlantıyı şifrelemek için kullandığı şeydir.
Aspose.Cells for Python via .NET, Microsoft Excel dosyalarını istediğiniz şifreleme türüyle şifreleyip parola koruma özelliği eklemenize izin verir.
Microsoft Excel Kullanımı
Microsoft Excel’de (burada Microsoft Excel 2003) dosya şifreleme ayarlarını yapmak için:
- Araçlar menüsünden Seçenekler‘i seçin. Bir iletişim kutusu görünecektir.
- Güvenlik sekmesini seçin.
- Bir parola girin ve Gelişmiş‘i tıklayın.
- Şifreleme türünü seçin ve parolayı onaylayın.
Aspose.Cells ile Şifreleme
Aşağıdaki örnek, Aspose.Cells for Python via .NET API kullanarak bir Excel dosyasını nasıl şifreleyip parola koruma altına alacağınızı gösterir.
from aspose.cells import EncryptionType, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Instantiate a Workbook object. | |
# Open an excel file. | |
workbook = Workbook(dataDir + "Book1.xls") | |
# Specify XOR encryption type. | |
workbook.set_encryption_options(EncryptionType.XOR, 40) | |
# Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider). | |
workbook.set_encryption_options(EncryptionType.STRONG_CRYPTOGRAPHIC_PROVIDER, 128) | |
# Password protect the file. | |
workbook.settings.password = "1234" | |
# Save the excel file. | |
workbook.save(dataDir + "encryptedBook1.out.xls") |
Değiştirilecek Parolayı Belirtme Seçeneği
Aşağıdaki örnek, mevcut bir dosya için Aspose.Cells for Python via .NET API kullanarak Değiştirmek için Parola Microsoft Excel seçeneğinin nasıl ayarlanacağını gösterir.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Instantiate a Workbook object. | |
# Open an excel file. | |
workbook = Workbook(dataDir + "Book1.xls") | |
# Set the password for modification. | |
workbook.settings.write_protection.password = "1234" | |
# Save the excel file. | |
workbook.save(dataDir + "SpecifyPasswordToModifyOption.out.xls") |
Şifrelenmiş dosyanın parolasını doğrulama
Şifreli dosyanın parolasını doğrulamak için, Aspose.Cells for Python via .NET, verify_password yöntemini sağlar. Bu yöntemler, iki parametre alır, dosya akışı ve doğrulanması gereken parola. Aşağıdaki kod parçası, sağlanan parolanın geçerli olup olmadığını doğrulamak için verify_password yönteminin nasıl kullanıldığını göstermektedir.
from aspose.cells import FileFormatUtil | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create a Stream object | |
fstream = open(dataDir + "EncryptedBook1.xlsx", "rb") | |
isPasswordValid = FileFormatUtil.verify_password(fstream, "1234") | |
print("Password is Valid: " + str(isPasswordValid)) |
ODS dosyasının Şifrelenmesi / Şifresinin Çözülmesi
Aspose.Cells for Python via .NET, ODS dosyasını şifreleyip şifresini çözmenize imkan tanır. Çözülen ODS dosyası hem Excel hem de OpenOffice’de açılabilir, ancak şifreli ODS dosyası yalnızca şifre girilerek OpenOffice tarafından açılabilir. Excel, şifreli ODS dosyasını açamaz ve uyarı mesajı gösterebilir. Şifreleme seçenekleri, diğer dosya türlerinin aksine, ODS dosyası için uygulanmaz. Bir ODS dosyasını şifrelemek için, dosyayı yükleyin ve kaydetmeden önce WorkbookSettings.password değerini gerçek şifre ile ayarlayın. Çıktı şifreli ODS dosyası yalnızca OpenOffice’te açılabilir.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Open an ODS file | |
workbook = Workbook(sourceDir + "sampleODSFile.ods") | |
# Password protect the file | |
workbook.settings.password = "1234" | |
# Save the ODS file | |
workbook.save(outputDir + "outputEncryptedODSFile.ods") |
ODS dosyasını çözmek için, dosyayı yüklemek için LoadOptions.password ile bir parola sağlayın. Dosya yüklendikten sonra, WorkbookSettings.password dizesini null olarak ayarlayın.
from aspose.cells import LoadFormat, LoadOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Open an encrypted ODS file | |
loadOptions = LoadOptions(LoadFormat.ODS) | |
# Set original password | |
loadOptions.password = "1234" | |
# Load the encrypted ODS file with the appropriate load options | |
workbook = Workbook(sourceDir + "sampleEncryptedODSFile.ods", loadOptions) | |
# Set the password to null | |
workbook.settings.password = None | |
# Save the decrypted ODS file | |
workbook.save(outputDir + "outputDecryptedODSFile.ods") |