简体   繁体   English

如何在java中使用sha-256计算XML标头和正文的校验和

[英]How to calculate checksum of XML header and body using sha-256 in java

I have a requirement to calculate checksum of the header and payload of the below XML using sha-256 and write it in the same XML at the trailer node(checksum element).我需要使用 sha-256 计算以下 XML 的标头和有效负载的校验和,并将其写入尾部节点(校验和元素)的相同 XML 中。 I have copied the source code in the below link.我复制了以下链接中的源代码。

How to convert CSV to XML in Java using JAXB 如何使用 JAXB 在 Java 中将 CSV 转换为 XML

I searched it in internet but could not find the solution I am looking for.我在互联网上搜索了它,但找不到我正在寻找的解决方案。 Most of them are reading the xml file from a physical location and converting it.他们中的大多数人正在从物理位置读取 xml 文件并进行转换。 However I don't write the XML in a file(it's only for reference not for any other purpose).但是我不会将 XML 写入文件中(仅供参考,不用于任何其他目的)。 I need to calculate the checksum of header and payload, then write it in the trailer section on the go and send it over to Solace topic.我需要计算标头和有效载荷的校验和,然后在旅途中将其写入预告片部分并将其发送到 Solace 主题。

How do I calculate the checksum data of header and body of an XML using sha-256?如何使用 sha-256 计算 XML 的标头和正文的校验和数据?

<?xml version='1.0' encoding='UTF-8'?>
<canonMessage xmlns="http://www.test.com/canon/v1">
    <header>
        <metadata>
            <domain>
                <name>party</name>
                <schemaVersion>1.0</schemaVersion>
                <subdomain>
                    <name>employee</name>
                </subdomain>
            </domain>
            <identifier>
                <id idScheme="HRSystem/lanId">SHawking</id>
            </identifier>
            <source>HRSystem</source>
            <messageId>84ec00d0-2a33-11eb-ae59-0050569a5c1d</messageId>
        </metadata>
    </header>
    <payload>
        <employee xmlns="http://www.test.com/party/employee/v1">
            <employeeId>79498</employeeId>
            <lanId>SHawking</lanId>
            <name>
                <lastName>Hawking</lastName>
                <firstName>Steve</firstName>
            </name>
            <businessTitle>Client Manager</businessTitle>
            <status>A</status>
            <groupName>Management</groupName>
            <departmentName>Legal</departmentName>
            <costCentre>RUSYDFGLEG</costCentre>
            <officeLocation>Texas</officeLocation>
            <region>US</region>
        </employee>
    </payload>
    <auditRecords>
        <sourceAuditRecord>
            <system>HRSystem</system>
            <timestamp>
                <created>2020-11-19T17:50:32.84+11:00</created>
                <sent>2020-11-19T17:50:32.84+11:00</sent>
            </timestamp>
        </sourceAuditRecord>
    </auditRecords>
    <trailer>
        <checksum type="sha-256">f60875e4905b62ed188ca61aee75fcfe354ae57fba4cabc8aba093d86a001569</checksum>
    </trailer>
</canonMessage>

XML Digital Signature XML 数字签名

The Java XML Digital Signature API is a standard Java API for generating and validating XML Signatures . Java XML 数字签名 API是用于生成和验证XML 签名的标准 Java API。

See XML Digital Signature API Overview and Tutorial请参阅XML 数字签名 API 概述和教程

The API is defined by JSR 105: XML Digital Signature APIs .该 API 由JSR 105:XML 数字签名 API 定义

The interface XMLSignature lets you sign and validate signatures. XMLSignature接口允许您签署和验证签名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM