java md5.computehash,在流腌制一个C#MD5 ComputeHash

I can't see any way to salt a MD5.ComputeHash(Stream).

Am I missing some way of injecting bytes into the HashAlgorithm?

I tried performing a ComputeHash(byte[]) before performing the stream compute, but, unsurprisingly, it had no effect. Any ideas (apart from modifying the file)?

Thanks for your time.

addendum

Just to be a little more specific, I want to use a stream to get a hash on a large file that I don't want to load into memory.

FileInfo myFI= new FileInfo("bigfile.dat");

FileStream myIFS = piFile.OpenRead();

MD5 md5 = MD5.Create();

byte[] hash = md5.ComputeHash ( myIFS );

myIFS.Close ();

解决方案

The answer to the lack of examples is in my opinion: you don't really need to salt it.

The hash algorithm like MD5 takes a table of bytes of arbitrary length and converts it to a table of bytes of known length - the operation is not easily reversible and small changes to the input table cause unpredictable changes in the output table:

input => MD5 => output

The purpose of salting is protection against attacks where user has already precomputed table of hash results (rainbow tables). By introducing small changes in the input, the results are change drastically, so even if attacker knows the hash result and the salt, it is very difficult to guess the input:

input + salt => MD5 => output

The reason for hashing files is to compute a checksum. E.g. you publish a file on your web page along with the hash result. User then downloads a file, runs it through MD5 and compares the result with your published result. It would be very difficult to tamper with the file, because each manipulation would change the resulting hash.

Salting is not necessary here, because you would have to publish the salt with the resulting hash, so that the user can repeat the hashing operation.

If you really need to introduce salting, just change the input stream in the repeatable way, e.g. add one (with overflow) to each byte.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值