我在Java中遇到DSS ESIG标志(https://github.com/esig/dss)的问题。我的代码如下:
DSSDocument doc = new InMemoryDocument(textToSign.getBytes(StandardCharsets.UTF_8));
String alias = getNotExpiredAlias();
PrivateKey privateKey = instance.getPrivateKey(alias);
DSSPrivateKeyEntry privateKeyEntry = new KSPrivateKeyEntry(new KeyStore.PrivateKeyEntry(privateKey, new Certificate[]{instance.getCertificate(alias)}));
XAdESSignatureParameters parameters = createSignatureParameters(privateKeyEntry, cryptoCardProvider.is64bit());
XAdESService service = new XAdESService(new CommonCertificateVerifier());
ToBeSigned dataToSign = service.getDataToSign(doc, parameters);
SignatureTokenConnection token = new AbstractSignatureTokenConnection() {
private ArrayList<DSSPrivateKeyEntry> keys;
@Override
public void close() {
keys = new ArrayList<>();
}
@Override
public List<DSSPrivateKeyEntry> getKeys() throws DSSException {
keys = new ArrayList<>();
keys.add(privateKeyEntry);
return keys;
}
};
DSSDocument dssDocument = service.signDocument(doc, parameters, token.sign(dataToSign, parameters.getDigestAlgorithm(), privateKeyEntry));
token.close();
return new String(DSSUtils.toByteArray(dssDocument));
这段代码的结果是:
<ds:Object Id=...>
但我需要:
<ds:Object Encoding="http://www.w3.org/2000/09/xmldsig#base64" Id=...>
如何为设置编码属性?对我而言,验证XML文档非常重要。我看不到要添加Encoding属性的设置方法。