Hash Functions (MD5, SHA-1, SHA-256)




GeeXLab - MD5, SHA-1, SHA-256 demo



If you need to compute MD5, SHA-1 or SHA-256 hash codes, GeeXLab has all you need.

Since GeeXLab 0.26+, it’s possible to calculate the hash codes (MD5, SHA-1, and SHA-256) of files and buffers. New hash codes generators will be likely added to GeeXLab in the future, but for the moment only these three hash codes generators are supported. Nice, they’re part of the most popular.

Here’s how to calculate the hash codes for files with GeeXLab and a bit of Lua (functions are also available in Python too):

-- "hashme.txt" is a regular file on the disk.
local demo_dir = gh_utils.get_demo_dir()
filename = demo_dir .. "hashme.txt"

zip_filename = "" -- no zip file

md5_hash = gh_utils.file_md5(zip_filename, filename)
sha1_hash = gh_utils.file_sha1(zip_filename, filename)
sha256_hash = gh_utils.file_sha256(zip_filename, filename)

 
Concretely, the hash codes returned by the previous functions are strings of characters.

It’s also possible to calculate the hash codes for simple strings (these functions are available in GeeXLab 0.26.3+):

md5_hash = gh_utils.md5("The quick brown fox jumps over the lazy dog")
sha1_hash = gh_utils.sha1("The quick brown fox jumps over the lazy dog")
sha256_hash = gh_utils.sha256("The quick brown fox jumps over the lazy dog")

 
The hash codes generated by the three previous function calls are:

MD5     => 9e107d9d372bb6826bd81d3542a419d6
SHA-1   => 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
SHA-256 => d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592

 
And for a memory buffer?

local demo_dir = gh_utils.get_demo_dir()
filename = demo_dir .. "hashme.txt"
buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)
if (buffer_size > 0) then
  file_md5_str = gh_utils.buffer_md5(buffer_ptr, buffer_size)
  file_sha1_str = gh_utils.buffer_sha1(buffer_ptr, buffer_size)
  file_sha256_str = gh_utils.buffer_sha256(buffer_ptr, buffer_size)
  gh_utils.buffer_kill(buffer_ptr)
end  

 
All these functions will be used in an upcoming tiny GeeXLab-based app for quickly generating hash codes for any file.

The demo

The demo that comes with this article is a direct implementation of this article. Download the demo and drag and drop it in GeeXLab. The zip archive can be directly loaded by GeeXLab.


GeeXLab - MD5, SHA-1, SHA-256 demo





2 thoughts on “Hash Functions (MD5, SHA-1, SHA-256)”

    1. JeGX Post Author

      Weird…

      I installed the latest total commander 9.21(a) 64-bit and the drag and drop from total commander has worked, no problem. I tested on a system with Windows 10 v1803 64-bit.

Leave a Reply to JeGX Cancel Reply

Your email address will not be published. Required fields are marked *