Hashing and digital signatures
Hashing protects integrity
- We hashed passwords for secrecy. Hashing also protects integrity — proving data was not changed.
- Change even one character of the input, and the hash changes completely.
Хэширование защищает целостность
- Мы хэшировали пароли для обеспечения секретности. Хэширование также защищает целостность — подтверждая, что данные не были изменены.
- Измените хотя бы один символ во входных данных, и хэш полностью изменится.
import hashlib
print(hashlib.sha256(b"hello").hexdigest()[:16])
print(hashlib.sha256(b"hellp").hexdigest()[:16]) # totally different
Checking a download
- Websites publish the hash of a file. After downloading, you hash your copy and compare.
- If the two hashes match, the file arrived intact. If not, it was corrupted or tampered with.
Проверка загрузки
- Сайты публикуют хэш файла. После скачивания вы хэшируете свою копию и сравниваете её.
- Если два хэша совпадают, файл прибыл целым. Если нет — он поврежден или был подменен.
Digital signatures
- A digital signature proves who sent something and that it was not changed.
- The sender hashes the message and encrypts that hash with their private key.
- Anyone can check it with the sender's public key — only the real sender could have made it.
Цифровые подписи
- Цифровая подпись доказывает кто отправил что-то и то, что это не было изменено.
- Отправитель хэширует сообщение и шифрует этот хэш своим закрытым ключом.
- Любой может проверить это с помощью открытого ключа отправителя — только настоящий отправитель мог создать эту подпись.
Your turn
- Compare the hashes of an original and a received message.
Truemeans the message is intact.
Covers: A-Level 17.1 (digital certification), 6.2 (integrity).
Ваша очередь
- Сравните хэши оригинального и полученного сообщения.
Trueозначает, что сообщение цело.
Охватывает: A-Level 17.1 (цифровая сертификация), 6.2 (целостность).
Common mistakes
- A hash is one-way — you cannot get the original back from it.
- A digital signature proves who sent a message and that it was not changed.
Распространенные ошибки
- Хэш является односторонним — вы не можете получить исходные данные обратно из него.
- Цифровая подпись доказывает, кто отправил сообщение, и что оно не было изменено.
Hashing & signatures
A hash is one-way and avalanches — perfect for fingerprints.
Check whether a received message is unchanged. Hash both original and received with SHA-256 and print whether the two digests are equal (True or False).
Click Run to see the output here. · Нажмите Запустить, чтобы увидеть результат здесь.
This time an attacker edited the message in transit. Hash both versions and print TAMPERED if the digests differ, else OK — one changed character is enough to catch.
Click Run to see the output here. · Нажмите Запустить, чтобы увидеть результат здесь.