我尝试将 Base64 字符串插入到 EnvelopedXmlObject 中的对象中:
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document document = dBuilder.newDocument();
String generatedDocument = ...;
BASE64Encoder encoder = new BASE64Encoder();
String generatedDocumentEncoded = encoder.encode(generatedDocument .getBytes("UTF-8"));
Node node1 = document.createTextNode(generatedDocumentEncoded);
DataObjectDesc dataObjectDesc = new EnvelopedXmlObject (node1, "plain/text", "http://www.w3.org/2000/09/xmldsig#base64");
....
当我在 file.xml 中运行此代码时,Object 的每一行都以“ ”结尾 导致解码文本错误
当我添加以下行时: Node node1 = document.createTextNode(generatedDocumentEncoded);
saveFile("c:\\temp\\temp.xml", generatedDocumentEncoded);
String stringFromFile = read("c:\\temp\\temp.xml");
node1.setTextContent(stringFromFile);
然后生成的文件就可以了-我的错误在哪里?:)