All Products
Search
Document Center

Object Storage Service:hash

Last Updated:Aug 13, 2024

This topic describes how to run the hash command to calculate the MD5 or CRC-64 hash of a local file.

Important

For ossutil V1.6.16 and later, you can directly use ossutil as the binary name in the command line. You do not need to update the binary name based on the system. For ossutil earlier than V1.6.16, you must specify a binary name that corresponds to the system. For more information, see ossutil command reference.

Command syntax

ossutil hash localfile [--type=<value>]

The following table describes the parameters and options in the command syntax.

Parameter/Option

Description

localfile

The full path of the local file.

--type

The algorithm used to calculate the hash of the local file. Valid values:

  • md5:

    If --type is set to md5, the MD5 hash and Content-MD5 value are displayed. The Content-MD5 value is obtained by calculating the MD5 hash to obtain a 128-bit number, and then encode the number in Base64. For more information about Content-MD5, see RFC 1864.

  • crc64 (default): if --type is set to crc64, the CRC-64 hash of the local file is calculated.

    For more information, see ECMA-182

After you upload the local file to the specified bucket as an object, take note of the following items when you want to query or use the CRC-64 or MD5 hash:

  • In the stat command, you can specify X-Oss-Hash-Crc64ecma to query the CRC-64 hash of the object and Content-Md5 to query the Content-MD5 field value of the object. For more information, see stat.

  • You cannot use the stat command to query the CRC-64 hash of an object that was uploaded to Object Storage Service (OSS) before CRC-64 is supported by OSS

  • You cannot use the stat command to query the Content-MD5 value of an object that was uploaded by using append upload or multipart upload.

Examples

  • Calculate the CRC-64 hash of a local file named test.txt:

    ossutil hash test.txt --type=crc64
    CRC64-ECMA                  : 295992936743767023
  • Calculate the MD5 hash of a local file named test.txt:

    ossutil hash test.txt --type=md5
     MD5                         : 01C3C45C03B2AF225EFAD9F911A33D73
     Content-MD5                 : AcPEXAOyryJe+tn5EaM9cw==