تعيين والتحقق من التواقيع الرقمية
يوفر التوقيع الرقمي الضمان بأن ملف ورق العمل صالح وأنه لم يقم أحد بتغييره. يمكنك إنشاء توقيع رقمي شخصي باستخدام أداة SELFCERT المرفقة مع حزمة Microsoft Office أو أي أداة أخرى. يمكنك حتى شراء توقيع رقمي. بعد إنشاء التوقيع الرقمي، يجب عليك إرفاقه بورق العمل الخاص بك. إرفاق توقيع رقمي مشابه لختم ظرف. إذا وصل ظرف مختوم، فإنك تمتلك بعض مستوى الضمان بأن لم يقم أحد بتلاعب محتوياته.
توفر واجهة برمجة التطبيق Aspose.Cells for Java الفئات com.aspose.cells.DigitalSignatureCollection و com.aspose.cells.DigitalSignature لتوقيع جداول البيانات بالإضافة إلى التحقق منها.
توقيع جداول البيانات
يتطلب عملية التوقيع شهادة كما تم مناقشته أعلاه. إلى جانب الشهادة، يجب على الشخص أيضًا أن يكون لديه كلمة مرور لتوقيع جداول البيانات بنجاح باستخدام واجهة برمجة التطبيق Aspose.Cells.
يوضح مقتطف الكود التالي استخدام واجهة برمجة التطبيق Aspose.Cells for Java لتوقيع جدول بيانات.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SigningSpreadsheets.class); | |
// Create an instance of DigitalSignatureCollection | |
DigitalSignatureCollection signatures = new DigitalSignatureCollection(); | |
// Load the certificate into an instance of InputStream | |
InputStream inStream = new FileInputStream("d:/temp.pfx"); | |
// Create an instance of KeyStore with PKCS12 cryptography | |
KeyStore inputKeyStore = KeyStore.getInstance("PKCS12"); | |
// Use the KeyStore.load method to load the certificate stream and its password | |
inputKeyStore.load(inStream, KEYSTORE_PASSWORD.toCharArray()); | |
// Create an instance of DigitalSignature and pass the instance of KeyStore, password, comments and time | |
DigitalSignature signature = new DigitalSignature(inputKeyStore, KEYSTORE_PASSWORD, "test for sign", | |
DateTime.getNow()); | |
// Add the instance of DigitalSignature into the collection | |
signatures.add(signature); | |
// Load an existing spreadsheet using the Workbook class | |
Workbook workbook = new Workbook(dataDir + "unsigned.xlsx"); | |
// Set the signature | |
workbook.setDigitalSignature(signatures); | |
// Save the signed spreadsheet | |
workbook.save(dataDir + "signed.xlsx"); |
التحقق من جداول البيانات
يوضح مقتطف الكود التالي استخدام واجهة برمجة التطبيق Aspose.Cells for Java للتحقق من جدول البيانات.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ValidatingSpreadsheets.class); | |
// Load an existing spreadsheet in an instance of Workbook | |
Workbook workbook = new Workbook(dataDir + "signed.xlsx"); | |
// Retrieve the collection of digital signatures from the Workbook | |
DigitalSignatureCollection signatures = workbook.getDigitalSignature(); | |
// Loop over the collection of digital signatures | |
for (DigitalSignature signature : (Iterable<DigitalSignature>) signatures) { | |
// Check the signature status using the isValid property | |
System.out.println(signature.isValid()); | |
} |