Hashing and digital signatures · Hashing e assinaturas digitais
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.
Hashing protege integridade
- Fazemos hash de senhas para sigilo. Hashing também protege integridade — provando que os dados não foram alterados.
- Mude até um único caractere da entrada e o hash muda completamente.
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.
Verificando um download
- Os sites publicam o hash de um arquivo. Após baixar, você faz o hash da sua cópia e compara.
- Se os dois hashes corresponderem, o arquivo chegou intacto. Se não, foi corrompido ou adulterado.
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.
Assinaturas digitais
- Uma assinatura digital prova quem enviou algo e que não foi alterado.
- O remetente faz o hash da mensagem e criptografa esse hash com sua chave privada.
- Qualquer um pode verificar com a chave pública do remetente — apenas o remetente real poderia tê-la feito.
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).
Sua vez
- Compare os hashes de uma mensagem original e recebida.
Truesignifica que a mensagem está intacta.
Cobertura: A-Level 17.1 (certificação digital), 6.2 (integridade).
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.
Erros comuns
- Um hash é one-way — você não pode recuperar o original a partir dele.
- Uma assinatura digital prova quem enviou uma mensagem e que não foi alterada.
Hashing & signatures · Hashing & assinaturas
A hash is one-way and · e avalanches — perfect for fingerprints. · Um hash é one-way (irreversível) e avalancheia — perfeito para impressões digitais.
Check whether a received message is unchanged. Hash both original and · e received with SHA-256 and print whether the two digests are equal (True or · ou False). · Verifique se uma mensagem recebida não foi alterada. Faça o hash de ambos original e received com SHA-256 e print se os dois digests são iguais (True ou False).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
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. · Desta vez um atacante editou a mensagem em trânsito. Faça o hash de ambas as versões e imprima TAMPERED se os digests diferirem, senão OK — basta um único caractere alterado para ser detectado.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.