简体   繁体   English

在Azure上传的blob的MD5哈希与本地计算机上的相同文件不匹配

[英]MD5 hash of blob uploaded on Azure doesnt match with same file on local machine

I am currently working on uploading media on Azure Blob storage. 我目前正致力于在Azure Blob存储上传媒体。 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). 一切正常,除非我尝试将上传媒体的MD5哈希与本地文件(完全相同的上传文件)进行混合。 Local file returns a byte array where are blob.Properties.ContentMD5 returns a string and both do not match. 本地文件返回一个字节数组,其中blob.Properties.ContentMD5返回一个字符串,两者都不匹配。

Local MD5 hash: sÔ(F¦‚"“Db~[N 本地MD5哈希: sÔ(F |,“”Db~ [N

blob.Properties.ContentMD5: c9QoHkamgiKTRANifltOGQ== 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. 这是一篇关于如何计算和检查Blob MD5校验和的好文章

I have faced this before, and I don't know why, but you can'T just do md5.computeHash(fileBytes) . 我以前遇到过这种情况,我不知道为什么,但你不能只做md5.computeHash(fileBytes) For Azure Blobs, it uses the following path to get the hash: 对于Azure Blob,它使用以下路径来获取哈希:

// 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. 是的,正如Guarav已经提到的那样 - MD5哈希被保存为base64字符串。

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

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