• Bonus activated 35% increased.
    Donate and get something hint hint.

[Tutorial] How to get a file hash

User_65561

Prestige 4
Registered
Lewd
Joined
Oct 19, 2023
Threads
5
Messages
253
Reaction score
678
LC COIN
9,403
I take no credit for this, it was posted on the other site, so I'm posting it here:

shark_inna_hat said:
Because of Reasons (see top of the page) - You all might be wondering how to get a file HASH, what it even is and why you might want to share it with your players each time you do a release.

What is a HASH?
I'm too lazy to write technical details myself so here's what Geepyti wrote:

A file hash is a unique string of characters that is generated by a mathematical algorithm (such as SHA256 or MD5) based on the contents of a file. It's like a digital fingerprint for the file. Even a tiny change in the file content will result in a completely different hash value.

File hashes are commonly used in computer security and verification processes. For example:
  1. Data Integrity: By comparing the hash of a file before and after transmission, you can ensure that the file has not been altered during transfer.
  2. Verification: Software downloads often come with a hash value provided by the creator. You can generate the hash of the downloaded file and compare it with the provided hash to verify that the file has not been tampered with.
  3. Password Storage: In security systems, passwords are often stored as hash values rather than plaintext. This adds an extra layer of security because even if someone gains access to the hash values, they cannot easily reverse-engineer them to obtain the original passwords.
In essence, a file hash serves as a reliable way to confirm the authenticity and integrity of a file.

Why you should share it?
If you give your player the hash of your zip (installer) they can easily check if the file they downloaded is the file you shared.

How to generate a Hash??
You could open up powershell, type in a bunch of code... or use this:
Code:
@echo off
setlocal enabledelayedexpansion

:: Check if a file is dropped onto the batch file
if "%~1"=="" (
    echo Please drop a file onto this batch file to calculate its hash.
    pause
    exit /b
)

:: Get the full path of the dropped file
set "file=%~1"

:: Get current timestamp
for /f "tokens=2 delims==." %%a in ('wmic OS Get localdatetime /value') do set "timestamp=%%a"

:: Format timestamp
set "timestamp=%timestamp:~0,4%-%timestamp:~4,2%-%timestamp:~6,2%_%timestamp:~8,2%-%timestamp:~10,2%-%timestamp:~12,2%"

:: Use PowerShell to calculate the hash
for /f "delims=" %%H in ('powershell.exe -command "(Get-FileHash '%file%' -Algorithm SHA256).Hash"') do set "hash=%%H"

:: Print hash to screen
echo Hash SHA256:
echo %hash%

:: Use PowerShell to write the hash, filename, and timestamp to file
powershell.exe -command "$hash = '%hash%'; $timestamp = '%timestamp%'; $filename = '%file%'; Write-Output \"Hash SHA256:`n$hash`n`nFile:`n$filename`n`nTimestamp:`n$timestamp\" | Out-File -FilePath '%file%.hash.txt' -Encoding utf8"

echo Hash written to "%file%.hash.txt"

pause
Save it as gib_me_hash_mr_shark.bat and just drag'n'drop your file onto it. It will print out the Hash to the console and also write a file that has the hash, timestamp and name of the file all in one place for your pleasure.

Let's make the net a safer place, so please always add the hash in your changelog, so that I know I'm pirating the real deal ;)


P.S. bat file written by AI. Sorry, not sorry, Me===Lazy.
P.P.S. :bat file corrected to be less stupid... because of AI, now it writes the actual filename not 'filename.txt' -_-'

Note you can name the .bat whatever you like, I named mine "SHA256.bat"

Would be nice if we had a game dev section (like the VIP section, but for game devs) where we could post this stuff..
 
  • Like
Reactions: 2 users
Another way to do this on Windows, using a built-in tool:
  1. Open command line (Win+X -> Terminal/Command Line), or Win+R: cmd.exe
  2. Run the command: certutil.exe -hashfile .\path\to\filename.zip sha256
    1. Note: Once you've written part of the command, you can insert the path to the file by drag-dropping the file to the command/terminal window.
(The use of the ".exe" extension is optional.)

You must be registered to see attachments
 
  • Like
Reactions: 1 user
I use a program called "HashTab". Once installed all you have to [in Windows] is right click on any file, go to Properties, and there is a tab called File Hashes. It will show you multiple Hash values for your file at once (CRC32, MD5, SHA-1, etc). You can use the Settings to adjust which values you want to see. You can also copy/paste the correct hash value right into the tab to confirm if it matches or not without having to check it manually.
 
Found an even easier way.

You can view the SHA-256 with :

You must be registered to see attachments
 
  • Like
Reactions: 1 users
Back
Top Bottom