Score:2

I don't quite understand hashing

id flag

I don't quite understand hashing, for encryption or otherwise.

So, if you have a website, and a user signs up, you store his password as a hash. When they log in, your website takes the submitted password, hashes it, and compares hashed submission to the stored hash, right?

Say you are hashing a sentence using SHA-256, do you EVER decrypt such a hash, or even have the ability to?

One last followup: Whatsapp says that my messages are encrypted. So, if I encrypt them as I send them, how does the other persons device decrypt them?

I realize this is a very general question, but I'm trying to wrap my head around how this works. Please don't yell.

et flag
No, a hash cannot be reversed. Hashing is a one-way operation. Hashing is not encryption.
meshcollider avatar
gb flag
Does this answer your question? [Differences between hash- and encryption algorithms?](https://crypto.stackexchange.com/questions/62036/differences-between-hash-and-encryption-algorithms)
Sheldon avatar
nl flag
**cryptographic hash function (CHF)** is a mathematical algorithm that maps data of an **arbitrary size** (often called the "**message**") to a bit array of a **fixed size** (the "hash value", "hash", or "**message digest**"). It is a **one-way** function, that is, a function for which it is practically infeasible to invert or reverse the computation.
kelalaka avatar
in flag
Yes, it is a too broad question and needs to have a very long answer and still one cannot be satisfied easily. WhatsApp? See this [In end-to-end encryption, doesn't the server need to be trusted?](https://crypto.stackexchange.com/q/54082/18298) and from WhatsApp: [WhatsApp Security Whitepaper](https://www.documentcloud.org/documents/2806301-WhatsApp-Security-Whitepaper-1)
Score:1
ng flag

So, if you have a website, and a user signs up, you store his password as a hash. When they log in, your website takes the submitted password, hashes it, and compares hashed submission to the stored hash, right?

Yes, with three additional details in the standard modern way of doing this:

  • The password reaches the website TLS-encrypted; it's decrypted before hashing.
  • Salt (random drawn on password registration, or/and the username/email) is hashed together with the password, and stored along the hash of the password by the server.
  • It's used a purposely slow, hopefully memory-hard iterated hash designed for passwords, like Argon2. This is designed as a protection in case the server lets the list of hashes and salt leak (such leaks happen routinely). This precaution makes it harder to find the password (or more exactly, an acceptable password most likely the original one) in a dictionary of usual passwords, by hashing candidates passwords and salt and comparing to the password hash, just as the server does to check a password on logon.

Say you are hashing a sentence using SHA-256, do you EVER decrypt such a hash, or even have the ability to?

No. For one, "decrypt" is not the correct term for finding the input of a hash function given it's output; the correct term is "reverse". And, a hash is designed to be irreversible in normal operation. If the hash's input is unknown and chosen randomly in a large set, and the hash design good, it's not practically possible to reverse the hash.


Whatsapp says that my messages are encrypted. So, if I encrypt them as I send them, how does the other persons device decrypt them?

Hashing is not the same thing as encryption. Hashing transforms a message in a way that is designed to be irreversible, and does not use a key. Encryption transforms a message according to an encryption key, in a way reversible by one with the decryption key.

The decryption key must be secret, else the goal of encryption (hiding what's been encrypted to adversaries not knowing the decryption key) is not met. In symmetric encryption (e.g. AES-GCM), the encryption and decryption keys are the same. In asymmetric encryption (e.g. RSA, ECIES), they are different: the encryption key can be made public, and is called the public key; the decryption key is the private key.

When you send a message with a modern application that uses asymmetric encryption (like Whatsapp), here is the big picture:

  • Your app draws a random symmetric message-unique key.
  • Your app encrypts the message using symmetric encryption with this message-unique key, and the result is sent.
  • Your app repeatedly encrypts the message-unique key towards each intended recipient, using asymmetric encryption (e.g. ECIES) and each of the intended recipient's public key, and the results are sent.
  • When a recipient needs to decrypt the message, their app first gets the encrypted message-unique key encrypted under their public key, and deciphers it (per asymmetric decryption) using their private key, yielding the message-unique key.
  • The recipient's app gets the encrypted message, decrypts it per symmetric decryption using the message-unique key, then display the decrypted message.

The primary mechanism protecting the confidentiality of the message is symmetric encryption. Asymmetric encryption protects the confidentiality of the message-unique key, thus indirectly protects the confidentiality of the message. Hashing typically is used internally as a building block in some of the steps, but is not the mechanism that encrypts the message or the message-unique key.

Score:0
kr flag

In addition to the answer of @frieu:

Say you are hashing a sentence using SHA-256, do you EVER decrypt such a hash, or even have the ability to?

To validate password you don't have to restore the password from the hash. You just compute a hash for the password that you want to check. If the password is the same, you will get the same hash.

Important is to know, that there can be more than one password that produces the same hash. But for algorithms like SHA-256 or Argon2 there are two important aspects:

  1. The probability that two passwords produce the same hash is very low.
  2. There is no analytical way to find some password that produces given hash. The only way is brute-forcing, i.e. trying all possible values. If the password has low entropy ("not random enough", to put it simply), e.g. if it has length of 8 characters, then its SHA-256 hash can be easily brute-forced. To prevent, it one should use algorithms that make brute-forcing very resource intensive, like Argon2.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.