您可以自己构建它,但我建议您像为 PDF 所做的那样使用库(XML 签名非常复杂)
检查esig-dss和这个示例SignXmlXadesBTest.java
//SERVER SIDE.
// Get the SignedInfo XML segment that need to be signed.
ToBeSigned dataToSign = service.getDataToSign(toSignDocument, parameters);
//CLIENT SIDE
// This function obtains the signature value for signed information using the
// private key and specified algorithm
SignatureValue signatureValue = signingToken.sign(dataToSign, parameters.getDigestAlgorithm(), privateKey);
// SERVER SIDE
// We invoke the service to sign the document with the signature value obtained in
// the previous step.
DSSDocument signedDocument = service.signDocument(toSignDocument, parameters, signatureValue);
在客户端,signingToken.sign() 只需使用私钥对服务器准备的摘要(字节数组)进行签名。如果您不使用 java,则不必使用 DSS,因为它是一种在大多数编程语言中都可用的简单加密操作
另请注意,DSS 可用作库或具有 REST 或 SOAP 接口的服务器