Supporto per la firma XAdES
Contents
[
Hide
]
Aspose.Cells fornisce il supporto per la firma dei fogli di lavoro con Firma XAdES. A tal scopo, l’API fornisce la classe DigitalSignature e l’enumerazione XAdESType.
Il seguente frammento di codice dimostra l’uso della classe DigitalSignature per firmare il foglio di lavoro di origine source.
Codice di Esempio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "sourceFile.xlsx"); | |
String password = "pfxPassword"; | |
String pfx = "pfxFile"; | |
// Load the certificate into an instance of InputStream | |
InputStream inStream = new FileInputStream(pfx); | |
// 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()); | |
DigitalSignature signature = new DigitalSignature(inputKeyStore, password, "testXAdES", com.aspose.cells.DateTime.getNow()); | |
signature.setXAdESType(XAdESType.X_AD_ES); | |
DigitalSignatureCollection dsCollection = new DigitalSignatureCollection(); | |
dsCollection.add(signature); | |
workbook.setDigitalSignature(dsCollection); | |
workbook.save(outputDir + "XAdESSignatureSupport_out.xlsx"); |