Skip to content

Instantly share code, notes, and snippets.

@angrygorilla
Forked from rob-murray/gen_http_cont_md5.rb
Created May 12, 2021 18:35
Show Gist options
  • Select an option

  • Save angrygorilla/199f4644a37a4416cd394efc7b0e2841 to your computer and use it in GitHub Desktop.

Select an option

Save angrygorilla/199f4644a37a4416cd394efc7b0e2841 to your computer and use it in GitHub Desktop.
Generate a base64 encoded md5 hash of a file in Ruby for use in http Content-MD5 header
require 'digest'
def main
raise ArgumentError, 'Please specify a file to work with' unless ARGV.length == 1
file_path = ARGV[0]
digest = Digest::MD5.base64digest(File.read( file_path ))
puts "The MD5 digest base64 encoded MD5 is #{digest} of file #{file_path}."
end
if __FILE__ == $0
main()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment