1. Hash a string
sha256sum reads stdin and prints a 256-bit one-way digest; -n drops the trailing newline so you hash exactly "data".
echo -n "data" | sha256sumTyporithm · medium
Step 1 of 8 · intro card
Cryptography
A cryptographic hash like SHA-256 is a one-way, collision-resistant fingerprint of data. HMAC mixes in a secret key so a tag proves integrity AND authenticity. Passwords need a slow, salted hash like bcrypt — never raw SHA-256.
A cryptographic hash maps any input to a fixed-size digest. SHA-256 is one-way (you cannot recover the input) and collision-resistant (you cannot find two inputs with the same digest), which makes it ideal for checking that data has not changed.
A plain hash proves integrity but not who produced it — anyone can recompute it. HMAC mixes a shared secret key into the hash, so a matching tag proves both that the data is intact and that it came from someone holding the key (authenticity).
Passwords are different: SHA-256 is far too fast, letting attackers try billions of guesses per second. Use a deliberately slow, salted algorithm such as bcrypt (here via htpasswd -B with cost 12) so each guess is expensive and identical passwords get different hashes.
SHA-256 is one-way and collision-resistant.
HMAC adds a secret key for integrity + authenticity.
Passwords need slow salted hashes (bcrypt), not raw SHA-256.
echo -n "data" | sha256sum
openssl dgst -sha256 file.txt
openssl dgst -sha256 -hmac "key" file.txt
htpasswd -bnBC 12 "" "pass"Connect each part of the code to the concept before you type.
sha256sum reads stdin and prints a 256-bit one-way digest; -n drops the trailing newline so you hash exactly "data".
echo -n "data" | sha256sumopenssl dgst -sha256 computes the SHA-256 digest of a file — used to verify a download was not corrupted.
openssl dgst -sha256 file.txtAdding -hmac "key" mixes a secret into the hash, so only holders of the key can produce or check the tag.
openssl dgst -sha256 -hmac "key" file.txt-B selects bcrypt and -C 12 sets the cost, producing a deliberately slow, salted password hash.
htpasswd -bnBC 12 "" "pass"Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.