मेरे पास एक्सेल फ़ाइल की सुरक्षा करने वाले पासवर्ड के बारे में कोई प्रश्न है।पासवर्ड में जावा में ज़िप्ड एक्सेल फ़ाइल की सुरक्षा कैसे करें?
स्थिति यह है कि, मेरे पास एक ज़िप फ़ाइल है, जिसमें इसमें एक्सेल फ़ाइल है। एक्सेल फ़ाइल की सुरक्षा के लिए मुझे जावा प्रोग्राम लिखना होगा। इसलिए, उपयोगकर्ता फ़ाइल को अनजिप करने में सक्षम होना चाहिए (ज़िप फ़ाइल को पासवर्ड सुरक्षित नहीं होना चाहिए)। लेकिन, एक्सेल को पासवर्ड-सुरक्षित होना चाहिए। जब उपयोगकर्ता फ़ाइल को अनजिप करने का प्रयास करता है, तो उसे ऐसा करने में सक्षम होना चाहिए। और जब वह एक्सेल फ़ाइल खोलने का प्रयास करता है (जो अनजिप किए गए फ़ोल्डर के अंदर है), तो उसे पासवर्ड मांगना होगा। प्रश्न Protect excel file with java के समान है, अतिरिक्त जटिलता के साथ, एक्सेल फ़ाइल ज़िपित है।
मेरे पास कोड है, वह पासवर्ड केवल ज़िप फ़ाइल की सुरक्षा करता है, लेकिन यह वही नहीं है जो मैं चाहता हूं।
import java.io.File;
import java.util.ArrayList;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;
/**
* Demonstrates adding files to zip file with standard Zip Encryption
*/
public class AddFilesWithStandardZipEncryption
{
public AddFilesWithStandardZipEncryption()
{
try {
// Initiate ZipFile object with the path/name of the zip file.
//ZipFile zipFile = new ZipFile("c:\\ZipTest\\AddFilesWithStandardZipEncryption.zip");
ZipFile zipFile = new ZipFile("C:\\homepage\\workspace\\PasswordProtectedFiles\\new.zip");
// Build the list of files to be added in the array list
// Objects of type File have to be added to the ArrayList
ArrayList filesToAdd = new ArrayList();
//filesToAdd.add(new File("C:\\homepage\\workspace\\passwordprotectedzipfile\\profile\\profile.txt"));
filesToAdd.add(new File("C:\\homepage\\workspace\\PasswordProtectedFiles\\new.xlsx"));
//filesToAdd.add(new File("c:\\ZipTest\\myvideo.avi"));
//filesToAdd.add(new File("c:\\ZipTest\\mysong.mp3"));
// Initiate Zip Parameters which define various properties such
// as compression method, etc.
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to store compression
// Set the compression level
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Set the encryption flag to true
// If this is set to false, then the rest of encryption properties are ignored
parameters.setEncryptFiles(true);
// Set the encryption method to Standard Zip Encryption
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
// Set password
parameters.setPassword("test123!");
// Now add files to the zip file
// Note: To add a single file, the method addFile can be used
// Note: If the zip file already exists and if this zip file is a split file
// then this method throws an exception as Zip Format Specification does not
// allow updating split zip files
zipFile.addFiles(filesToAdd, parameters);
}
catch (ZipException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new AddFilesWithStandardZipEncryption();
}
}
संपीड़ित फ़ाइल में पासवर्ड सुरक्षा जोड़ने का कोई तरीका हो सकता है बिना इसे दबाए , लेकिन इसे संभालने का एकमात्र तरीका यह है कि इसे डिकंप्रेस करें, फिर पासवर्ड सुरक्षा के साथ इसे फिर से दबाएं। ज़िप स्थिति का पालन करने की आवश्यकता होने पर पासवर्ड सुरक्षा को संभालने के लिए आपको ज़िप स्पेक में खोदना पड़ सकता है। –
आप एक .xlsx फ़ाइल क्यों ज़िपित कर रहे हैं? .xlsx पहले से ही एक ज़िप फ़ाइल है, आपको बहुत कुछ नहीं मिलेगा! – AxFab
मुझे आपके उपयोग-मामले को नहीं पता है, लेकिन केवल यह मान लें कि ज़िप की सुरक्षा करने वाला पासवर्ड सुरक्षित है, क्योंकि इसमें केवल "पासवर्ड" नहीं जोड़ा जाएगा, बल्कि पूरी चीज़ को एन्क्रिप्ट किया जाएगा। यह भी मान लें कि एक्सेल के कुछ संस्करण वास्तव में असुरक्षित हैं: http://www.excelforum.com/excel-programming/503874-how-safe-is-the-excel-password-functionality.html। अगर सुरक्षा आपके लिए एक मुद्दा है, तो आप ज़िप एन्क्रिप्शन के साथ बेहतर रहेंगे। –