生成在C#中的XML文档的哈希 [英] Generating an XML document hash in C#

查看:204
本文介绍了生成在C#中的XML文档的哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是去在C#哈希的XML文档的最佳方式?我想凑一个XML文档,这样我可以告诉大家,如果它是手动生成时,它改变了。我没有使用这个安全 - 这是确定的,如果有人改变了XML,并改变了哈希匹配



例如,我会散列子节点根和散列存储为根的一个属性:

 <的RootNode哈希=ABC123> 
<! - 内容在这里哈希 - >
< /&的RootNode GT;


解决方案

.NET具有的classes 实现了 XML数字签名规范。可以在原始XML文档中添加签名(即一个笼罩签名),或存储/单独转让。



这可能是一个有点矫枉过正,因为你不吨需要的安全性,但它有被已实施的优点,并且是不依赖于语言或平台的标准。


What's the best way to go about hashing an XML document in C#? I'd like to hash an XML document so that I can tell if it was manually changed from when it was generated. I'm not using this for security--it's OK if someone changes the XML, and changes the hash to match.

For example, I'd hash the child nodes of the root and store the hash as an attribute of the root:

<RootNode Hash="abc123">
    <!-- Content to hash here -->
</RootNode>

解决方案

.NET has classes that implement the XML digital signature spec. The signature can be added inside the original XML document (i.e. an "enveloped signature"), or stored/transferred separately.

It may be a bit overkill since you don't need the security, but it has the advantage of being already implemented, and being a standard which does not depend on a language or platform.

这篇关于生成在C#中的XML文档的哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆