gpt4 book ai didi

java - 在 Android 中使用 XAdeS-BES 进行签名

转载 作者:行者123 更新时间:2023-12-01 06:08:45 25 4
gpt4 key购买 nike

我正在尝试在 Android 中使用 XADES-BES 签署文件。我找到了一个关于这个的图书馆。构建和创建 APK 工作正常。选择文件并单击“签名”按钮后,出现运行时错误。经过调试发现Context有错误。我在程序崩溃的地方添加了评论。相关部分代码如下:

 String sourceFilePath = filePathView.getText().toString();
if(sourceFilePath.isEmpty()){
exc = new Exception("No File Picked");
return null;
}
mAPDUSmartCard.login(pwdText);
Pair<CardTerminal,ECertificate> selection = certListAdapter.getSelection();
ECertificate signCert = selection.second;
BaseSigner signer = mAPDUSmartCard.getSigner(signCert.asX509Certificate(), Algorithms.SIGNATURE_RSA_SHA256);
Context context = new Context();
XMLSignature signature = new XMLSignature(context); // THIS IS WHERE THE APP CRASHES.
signature.addDocument(sourceFilePath,"application/xml", false);
signature.getSignedInfo().setSignatureMethod(SignatureMethod.RSA_SHA256);
signature.addKeyInfo(signCert);
signature.sign(signer);
signature.write(new FileOutputStream(sourceFilePath + ".xsig"));

我没有使用 Xades4j lib,因为我不知道如何将此代码转换为适合 cades4j lib 的形式。

最佳答案

我不知道您正在使用的库,但关于 xades4j,您可以按照 project wiki 上的文档进行操作。从您的代码来看,这似乎是一个 xades4j 应该支持的简单场景。

关于java - 在 Android 中使用 XAdeS-BES 进行签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39035546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com