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

后端 未结 1 1052
栀梦
栀梦 2021-01-18 05:52

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 s

相关标签:
1条回答
  • 2021-01-18 06:28

    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.

    0 讨论(0)
提交回复
热议问题