我需要用 XAdES-EPES 封装的 xml 文件签名,RSA-SHA256 使用这个哈希: Quzn98x3PMbSHwbUzaj5f5KOpiH0u8bvmwbbbNkO9Es
我签署了 XML,但它无效,因为我不知道如何输入该哈希。这是我的代码:
public class Firma{
private static final String FOLDER = "C:/ECLIPSE/PRUEBAS_Firma/";
private static final String CERT = "SOLDISP_XXXXX.p12";// "Certificado de
// dispositivo
private static final String PASS = "xxxxxx";
private static final String DOCUMENT = "C:/ECLIPSE/PRUEBAS_Firma/Ejemplo_TicketBAI_B00000034_B2022_0101_SinFirma.xml";
public static void main(String[] args) throws Exception {
System.setProperty("org.apache.xml.security.ignoreLineBreaks", "true");
System.out.println(">>>>>>>>> Firmando XML");
signEpes();
}
private static void signEpes() throws Exception {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(DOCUMENT));
Element elem = doc.getDocumentElement();
DOMHelper.useIdAsXmlId(elem);
KeyingDataProvider kdp = new FileSystemKeyStoreKeyingDataProvider("pkcs12", FOLDER + CERT,
new FirstCertificateSelector(), new DirectPasswordProvider(PASS), new DirectPasswordProvider(PASS),
true);
// politica
SignaturePolicyInfoProvider policyInfoProvider = new SignaturePolicyInfoProvider() {
@Override
public SignaturePolicyBase getSignaturePolicy() {
return new SignaturePolicyIdentifierProperty(
new ObjectIdentifier(
"https://www.batuz.eus/fitxategiak/batuz/ticketbai/sinadura_elektronikoaren_zehaztapenak_especificaciones_de_la_firma_electronica_v1_0.pdf",
IdentifierType.URI, ""),
new ByteArrayInputStream(
"https://www.batuz.eus/fitxategiak/batuz/ticketbai/sinadura_elektronikoaren_zehaztapenak_especificaciones_de_la_firma_electronica_v1_0.pdf"
.getBytes())
);
}
};
SignerEPES signer = (SignerEPES) new XadesEpesSigningProfile(kdp, policyInfoProvider).newSigner();
new Enveloped(signer).sign(elem);
outputDocument(doc, "Factura_firmada.xml");
}
protected static void outputDocument(Document doc, String fileName) throws Exception {
TransformerFactory tf = TransformerFactory.newInstance();
File outDir = ensureOutputDir();
FileOutputStream out = new FileOutputStream(new File(outDir, fileName));
tf.newTransformer().transform(new DOMSource(doc), new StreamResult(out));
out.close();
}
private static File ensureOutputDir() {
File dir = new File(toPlatformSpecificFilePath(FOLDER));
dir.mkdir();
return dir;
}
}
拜托,谁能帮帮我???提前致谢