Agregar firma digital a un archivo de Excel ya firmado
Posibles escenarios de uso
Aspose.Cells proporciona elWorkbook.addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) que puede usar para agregar una firma digital a un archivo de Excel ya firmado.
Agregar firma digital a un archivo de Excel ya firmado
El siguiente código de ejemplo explica cómo hacer uso deWorkbook.addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) para agregar una firma digital a un archivo de Excel ya firmado. Por favor, checa elejemplo de archivo de Excelutilizado en este código. Este archivo ya está firmado digitalmente. Por favor, checa elarchivo de salida de Excelgenerado por el código. Hemos utilizado el certificado de demostración llamadoAsposePrueba.pfxen este código que tiene una contraseñasuponerLa captura de pantalla muestra el efecto del código de muestra en el archivo de Excel de muestra después de la ejecución.
Código de muestra
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Certificate file and its password | |
String certFileName = "AsposeTest.pfx"; | |
String password = "aspose"; | |
// Load the workbook which is already digitally signed to add new digital signature | |
Workbook workbook = new Workbook(srcDir + "sampleDigitallySignedByCells.xlsx"); | |
// Create the digital signature collection | |
DigitalSignatureCollection dsCollection = new DigitalSignatureCollection(); | |
// Create new digital signature and add it in digital signature collection | |
// ------------------------------------------------------------ | |
// --------------Begin::creating signature--------------------- | |
// Load the certificate into an instance of InputStream | |
InputStream inStream = new FileInputStream(srcDir + certFileName); | |
// Create an instance of KeyStore with PKCS12 cryptography | |
java.security.KeyStore inputKeyStore = java.security.KeyStore.getInstance("PKCS12"); | |
// Use the KeyStore.load method to load the certificate stream and its password | |
inputKeyStore.load(inStream, password.toCharArray()); | |
// Create an instance of DigitalSignature and pass the instance of KeyStore, password, comments and time | |
DigitalSignature signature = new DigitalSignature(inputKeyStore, password, | |
"Aspose.Cells added new digital signature in existing digitally signed workbook.", | |
com.aspose.cells.DateTime.getNow()); | |
dsCollection.add(signature); | |
// ------------------------------------------------------------ | |
// --------------End::creating signature----------------------- | |
// Add digital signature collection inside the workbook | |
workbook.addDigitalSignature(dsCollection); | |
// Save the workbook and dispose it. | |
workbook.save(outDir + "outputDigitallySignedByCells.xlsx"); | |
workbook.dispose(); |