在Azure上上传的blob的MD5哈希不会与本地计算机上的相同文件匹配 [英] MD5 hash of blob uploaded on Azure doesnt match with same file on local machine

查看:195
本文介绍了在Azure上上传的blob的MD5哈希不会与本地计算机上的相同文件匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正致力于在Azure Blob存储上上传媒体。除了当我尝试使用本地文件(与上传的完全相同)上传媒体的MD5哈希值时,所有工作都正常。本地文件返回一个字节数组,其中blob.Properties.ContentMD5返回一个字符串,两者不匹配。



本地MD5哈希值:sÔ(F|,Db〜[N / b>

blob.Properties.ContentMD5: c9QoHkamgiKTRANifltOGQ ==



任何可能的方式来匹配这两个?

解决方案

这是一篇很好的文章,介绍如何计算和检查Blob MD5校验和。



,并且我不知道为什么,但是您不能只执行 md5.computeHash(fileBytes)
对于Azure Blob,它使用以下路径获取哈希:

$ $ p $ //验证MD5值
var md5Check = System.Security.Cryptography.MD5.Create( );
md5Check.TransformBlock(retrieveBuffer,0,retrievedBuffer.Length,null,0);
md5Check.TransformFinalBlock(new byte [0],0,0);

//获取哈希值
byte [] hashBytes = md5Check.H ash;
string hashVal = Convert.ToBase64String(hashBytes);

它可以工作......

是的,正如Guarav已经提到的 - MD5哈希值被保存为base64字符串。


I am currently working on uploading media on Azure Blob storage. All is working fine except when i try to macth the MD5 hash of uploaded media with the local file (exactly same one which was uploaded). Local file returns a byte array where are blob.Properties.ContentMD5 returns a string and both do not match.

Local MD5 hash: sÔ(F¦‚""Db~[N

blob.Properties.ContentMD5: c9QoHkamgiKTRANifltOGQ==

Any possible way to match both these?

解决方案

Here is a good article on how to calculate and check Blob MD5 checksums.

I have faced this before, and I don't know why, but you can'T just do md5.computeHash(fileBytes). For Azure Blobs, it uses the following path to get the hash:

// Validate MD5 Value
var md5Check = System.Security.Cryptography.MD5.Create();
md5Check.TransformBlock(retrievedBuffer, 0, retrievedBuffer.Length, null, 0);     
md5Check.TransformFinalBlock(new byte[0], 0, 0);

// Get Hash Value
byte[] hashBytes = md5Check.Hash;
string hashVal = Convert.ToBase64String(hashBytes);

and it works...

And yes, as Guarav already mentioned - MD5 hash is saved as base64 string.

这篇关于在Azure上上传的blob的MD5哈希不会与本地计算机上的相同文件匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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