Java Android:xadesuri错误

Java Android:xadesuri错误,java,android,xml-signature,xades4j,Java,Android,Xml Signature,Xades4j,我正在用Android Studio开发xades bes类型签名。我使用的库不是xades4j。我国政府提供了另一个jor java图书馆,我正在使用它。我正在尝试对XML文件进行签名 我在/raw目录中有一个用于我的xades签名的XML文件(不是测试文件): 2000 http://tzd.kamusm.gov.tr SHA-256 用户id 密码 http://www.w3.org/2001/04/xmlenc#sha256 0 17280000 假的 真的 假的 假的 假的 在我的

我正在用Android Studio开发xades bes类型签名。我使用的库不是xades4j。我国政府提供了另一个jor java图书馆,我正在使用它。我正在尝试对XML文件进行签名

我在/raw目录中有一个用于我的xades签名的XML文件(不是测试文件):


2000
http://tzd.kamusm.gov.tr
SHA-256
用户id
密码
http://www.w3.org/2001/04/xmlenc#sha256
0
17280000
假的
真的
假的
假的
假的
在我的mainActivity类中,代码的相关部分是:

 String sourceFilePath = filePathView.getText().toString();
                if (sourceFilePath.isEmpty()) {
                    exc = new Exception("No File Selected.");
                    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);    

                Resources res1 = getResources();
                Config conf = new Config ( res1.openRawResource(R.raw.xmlsignature_config));
                Context context = new Context();
                context.setConfig(conf);

                XMLSignature signature = new XMLSignature(context);

                signature.addDocument( sourceFilePath, "application/xml", false);  // This part's first parameter can be the reason of error. 
                        signature.getSignedInfo().setSignatureMethod(SignatureMethod.RSA_SHA256);
                signature.addKeyInfo(signCert);
                signature.sign(signer);
                signature.write(new FileOutputStream(sourceFilePath + ".xsig"));
String sourceFilePath=filePathView.getText().toString();
if(sourceFilePath.isEmpty()){
exc=新异常(“未选择任何文件”);
返回null;
}
mAPDUSmartCard.login(pwdText);
Pair selection=certListAdapter.getSelection();
ECertificate signCert=selection.second;
BaseSigner signer=mAPDUSmartCard.getSigner(signCert.asX509Certificate(),Algorithms.SIGNATURE\u RSA\u SHA256);
Resources res1=getResources();
Config conf=new Config(res1.openrawsource(R.raw.xmlsignature_Config));
上下文=新上下文();
context.setConfig(conf);
XMLSignature=新的XMLSignature(上下文);
signature.addDocument(sourceFilePath,“application/xml”,false);//这部分的第一个参数可能是错误的原因。
signature.getSignedInfo().setSignatureMethod(SignatureMethod.RSA_SHA256);
签名。addKeyInfo(签名证书);
签名。签名(签名者);
signature.write(新文件输出流(sourceFilePath+“.xsig”);
程序正在运行。但是,当我选择文件并单击“签名”按钮时:

1-我遇到了一个引用错误,日志中说uri找不到sourceFilePath变量的路径,该变量是要签名的文件的路径。 它还提供了一个带有错误的引用id。 当我给出一个空字符串(“”)而不是sourceFilePath变量时,程序会说该文件已签名(我不明白如果不在addDocument方法中给出参数,如何对其进行签名。无论如何,已签名文件的验证程序不会验证该文件,因为存在引用未找到错误

2-也在我的xml文件中xmlns=”http://uekae.tubitak.gov.tr/xml/signature#第行给出了“Uri未注册”错误。我已经完成了我在这里发现的操作,但问题没有解决。这种情况是否是我面临错误的原因

我已经在这个问题上工作了好几天,但仍然找不到任何解决方案

 String sourceFilePath = filePathView.getText().toString();
                if (sourceFilePath.isEmpty()) {
                    exc = new Exception("No File Selected.");
                    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);    

                Resources res1 = getResources();
                Config conf = new Config ( res1.openRawResource(R.raw.xmlsignature_config));
                Context context = new Context();
                context.setConfig(conf);

                XMLSignature signature = new XMLSignature(context);

                signature.addDocument( sourceFilePath, "application/xml", false);  // This part's first parameter can be the reason of error. 
                        signature.getSignedInfo().setSignatureMethod(SignatureMethod.RSA_SHA256);
                signature.addKeyInfo(signCert);
                signature.sign(signer);
                signature.write(new FileOutputStream(sourceFilePath + ".xsig"));