0
我想在Android中使用XADES-BES签名文件。我找到了一个关于这个的图书馆。建立和创建APK工作正常。选择文件并单击Sign按钮后,它会产生运行时错误。调试后,我发现有一个关于上下文的错误。我在程序崩溃的地方添加了一条评论。代码的相关部分如下:在Android中使用XAdeS-BES签名
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库。
好的,我会仔细阅读文档,并尝试将我的代码转换为xades4j。谢谢。 –