关于xml签名问题,xmlsec读取

<?xml  version="1.0"  encoding="UTF-8"?>

<document>

<request id="request">

<head>

<version>1.0.0</version>

<appid>SHHRSS71</appid>

<function>xxxx.medical.card.query</function>

<reqTime>20160229105541</reqTime>

<reqTimeZone>UTC+8</reqTimeZone>

<reqMsgId>20160229104541129849135077530072</reqMsgId>

</head>

<body>

<out_order_no>201507137646513821856579626</out_order_no>

<user_id />

<user_type />

<real_name />

</body>

</request>

<signature>2ad0205bfe5d338ac60bf7805670a877dda66f38b168e7479b27f51991f938bd26901782f691d290cc54629294be1b337e57071e38de5ef5eae6d79ec5a09bca5a0af5112f70a0e3df28e2e1c304755b98b0a32a4d1ebb243fc311ce3771803d96a2adaddf63d88686ba97528170e3487dd809fe202d5ab6ad72f2d2ddce3dddcb55943409ef6ff93bc98b8c782502b27675b3f88413c6249899f3e33194c29707d403a1e2fee66513ed1407e032d6dcb3347ab0d00cf21508ed367f49985f605bb1eeef66f92948e4fa4a3c2eda170d98b4e59646d9a59a50dd8ecdf7ad9e0e61723dc29ef8e9628aac56a35afaa2839acc1655276fb38e2f2fa1a6cc9c5a1b</signature>

</document>

这种格式的xml,签名验证,我要拿到signature的值,和request部分,用xmlsec怎么写呢? 是不是签名验证都要用xmlsec来读取xml数据?

回答:

图片描述

    <dependencies>

<dependency>

<groupId>xml-security</groupId>

<artifactId>xmlsec</artifactId>

<version>1.0.5D2</version>

</dependency>

<dependency>

<groupId>dom4j</groupId>

<artifactId>dom4j</artifactId>

<version>1.6.1</version>

</dependency>

</dependencies>

pom.xml文件中添加依赖

package tt;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.InputStreamReader;

public class Test {

public static void main(String[] args) {

File file = new File("D:/a.txt");

try {

InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), "GBK");

BufferedReader bufferReader = new BufferedReader(inputStreamReader);

String lineTXT = null;

String signature = null;

while ((lineTXT = bufferReader.readLine()) != null) {

if (lineTXT.trim().startsWith("<signature>")) {

signature = lineTXT.trim().substring(11, lineTXT.trim().length() - 12);

System.out.println(signature);

}

}

bufferReader.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}

以上是 关于xml签名问题,xmlsec读取 的全部内容, 来源链接: utcz.com/p/181952.html

回到顶部