Skip to main content

digest.sha1

The digest.sha1 function returns the SHA-1 digest of a string as lowercase hexadecimal. SHA-1 is not collision resistant, so use it only where another system already expects it, such as Git object ids or legacy checksum files. For fingerprints you control, use digest.sha256.

Usage​

digest.sha1(data)

Arguments​

data
Required. The string to hash, as bytes.

Returns​

The digest as a 40-character lowercase hexadecimal string.

Example​

Compute a Git blob id without Git​

content = fs.read_file("README.md")
blob = digest.sha1("blob " + str(len(content)) + "\0" + content)

Errors​

  • A missing argument, or an argument that is not a string, fails with an argument error.