Skip to content

Instantly share code, notes, and snippets.

@cworld1
Created October 7, 2024 17:47
Show Gist options
  • Save cworld1/ace2f133a640df899d2f9479015edb84 to your computer and use it in GitHub Desktop.
Save cworld1/ace2f133a640df899d2f9479015edb84 to your computer and use it in GitHub Desktop.
A bat script to calc MD5 or SHA1/256 hash for Windows users. No additional requirements need.
@echo off
:: Display a simple logo
echo.
echo ================================
echo Hash Calculator
echo ================================
echo.
:loop
:: Check if a file path is provided as an argument
if "%~1"=="" (
set /p filePath="> Enter file path or drag file here: "
) else (
set filePath="%~1"
)
:: Remove quotes for checking existence
set filePathNoQuotes=%filePath:"=%
if not exist %filePathNoQuotes% (
echo File does not exist, please re-enter.
goto loop
)
set /p choice="> Enter your choice 1. MD5, 2. SHA1, 3. SHA256(Default): "
:: Default to SHA256 if no input
if "%choice%"=="" (
set choice=3
)
if "%choice%"=="1" (
certutil -hashfile %filePathNoQuotes% MD5
) else if "%choice%"=="2" (
certutil -hashfile %filePathNoQuotes% SHA1
) else if "%choice%"=="3" (
certutil -hashfile %filePathNoQuotes% SHA256
) else (
echo Invalid option, please select again.
)
echo.
goto loop
@cworld1
Copy link
Author

cworld1 commented Oct 7, 2024

You can:

  1. Run script and input path / drag file
  2. Drag file to the script itself or its shortcut

If you only press enter without input anything when hash choices, it will default on SHA256.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment