生成在C#中运行哈希(或校验)? [英] Generate Running Hash (or Checksum) in C#?

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

问题描述

前言:

我做的一个数据导入具有验证提交阶段。其思想是:第一阶段允许采取各种来源的数据,然后运行的各种插入/更新/校验数据库上操作。提交被回退,但产生一个验证哈希/校验。提交阶段是相同的,但是,如果验证哈希/校验和是一样的那么操作将被提交。 (该数据库将在适当的隔离级别上运行。)

I am doing a data-import that has a verify-commit phase. The idea is that: the first phase allows taking data from various sources and then running various insert/update/validate operations on a database. The commit is rolled back but a "verification hash/checksum" is generated. The commit phase is the same, but, if the "verification hash/checksum" is the same then the operations will be committed. (The database will be running under the appropriate isolation levels.)

限制:


    <李>输入阅读和操作前进读一次只能
  • 请不要想预先创建一个流(如写入MemoryStream的不可取的),因为可能会有的很多的数据。 (它的工作对我们的服务器/负载,但假装记忆是有限的。)

  • 请不要想创造我自己的。 (我知道像 CRC-32达米安我可以使用哪些可用的代码/修改,但会喜欢的东西标准)

  • Input reading and operations are forward-read-once only
  • Do not want to pre-create a stream (e.g. writing to MemoryStream not desirable) as there may be a lot of data. (It would work on our servers/load, but pretend memory is limited.)
  • Do not want to "create my own". (I am aware of available code like CRC-32 by Damien which I could use/modify but would prefer something "standard".)

和寻找什么,我(想我):

And what I (think I am) looking for:

生成基于输入+操作的哈希(如SHA1或MD5?),或校验(如CRC32但希望更多)的方法。 (输入/操作可能会自行散列到值更贴合校验代,但它会很美好,只是为了能够写蒸。)

A way to generate a Hash (e.g. SHA1 or MD5?) or a Checksum (e.g. CRC32 but hopefully more) based on input + operations. (The input/operations could themselves be hashed to values more fitting to the checksum generation but it would be nice just to be able to "write to steam".)

所以, ,问题是:

如何生成在C#中正在运行的哈希(或校验)

另外,虽然有CRC32实现,可以为运行的操作进行修改,有关运行SHAx或MD5哈希值是什么?

Also, while there are CRC32 implementations that can be modified for a Running operation, what about running SHAx or MD5 hashes?

我缺少某种比可以作为一个适配器方便流的方法呢?

Am I missing some sort of handy Stream approach than could be used as an adapter?

(影评欢迎,还请回答上述适用的。而且,我宁愿不处理线程; - )

(Critiques are welcome, but please also answer the above as applicable. Also, I would prefer not to deal with threads. ;-)

推荐答案

哈希有一个构建和定稿阶段。您可以在构建阶段推任意数量的数据。只要你喜欢的数据可以拆分。最后,完成哈希运算,让你的哈希值。

Hashes have a build and a finalization phase. You can shove arbitrary amounts of data in during the build phase. The data can be split up as you like. Finally, you finish the hash operation and get your hash.

您可以使用一个可写的的CryptoStream 写您的数据。 这是最简单的方法。

You can use a writable CryptoStream to write your data. This is the easiest way.

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

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