Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
What goes into a great hash?
Hashing is a one-way street; data that has been hashed cannot be unhashed. Some hashing algorithms, though, have been compromised through what's known as hash collisions. This is where two different inputs can generate the same hash. More damaging are chosen-prefix collision attacks, where attackers can use a known part of a document to generate a hash that matches another, valid document. Using this, they can spoof encryption keys and other symmetrically-encrytped documents.
To combat both of these, we add salts to our hashes and use hashing algorithms that either have no known (yet) collisions or stress the machines used to compute them. Both of these techniques can dissuade attackers.
Shattered
I misspoke in the video and said the SHA-1 collision detection came out of Adobe. It was actually discovered at Google by Project Zero/Google Research Security. You can find out more here.
-
0:00
One way to keep data safely stored is to make it unreadable and unrecoverable.
-
0:04
Now that might not make much sense but
-
0:06
it all depends on what you need to do with the data.
-
0:08
You probably want to keep your users data in format that they can read, but
-
0:11
do you need to do that with their password?
-
0:12
No, not really.
-
0:15
Hashing is a wide area that a lot of application such as checksounds
-
0:18
validate and file contents, lastly compression and message authentication.
-
0:22
One of the most common though is to reliably encode data.
-
0:25
This is done with something known as a hash function which takes in data
-
0:28
using one or more algorithms, turns that data into a hash.
-
0:32
The same data in the same hash function will produce the same hash every time.
-
0:36
Seems like a great way to safely store your sensitive data?
-
0:39
It certainly can be, but if you need to get that data back, you're out of luck.
-
0:43
Hashing is a one way street and data that's been hashed can't be unhashed.
-
0:47
This is the feature though, since we can use hashing on data that we really
-
0:50
shouldn't be able to read but need to verify.
-
0:52
Take passwords for example.
-
0:54
As a service like Amazon or Twitter, I should never know what your password is.
-
0:57
I should take it, hash it, and store that hash in my database.
-
1:01
Then when you want to log in, I take the password you give me, hash it the same way
-
1:04
and compare the resulting hash to what I have stored in the database.
-
1:07
If it's the same, then great, you're you.
-
1:09
If they're not, well, I'm not gonna let you in.
-
1:12
You might have just thought of another problem with hashing.
-
1:14
If you and I both share the same password on a site and I try to log in to
-
1:17
your account, our hashes would match, I just got into your account.
-
1:21
Thankfully, most hashing algorithm have a feature known as a salt.
-
1:24
A salt is a bit of unique data, like maybe the Unix time stamp of when we signed up
-
1:28
that's added to every hash that will change the output.
-
1:31
Now, even though we have the same characters in our password,
-
1:33
since we each have a different salt, the hash comes out differently.
-
1:37
There are a lot of hash functions out there with a various degrees of
-
1:39
difficulty to them.
-
1:40
By degree of difficulty, I mean how hard the resulting hash is to break or reverse.
-
1:45
Many of them would require more computing time
-
1:47
than an attacker would consider reasonable.
-
1:49
There are some hash functions though that are now considered insecure.
-
1:52
The MD5 algorithm, for example, was a very commonly used hash function in the earlier
-
1:57
days of the modern worldwide web.
-
1:59
It's now considered to be severely compromised though,
-
2:01
as it doesn't require a large amount of computing power to find collisions between
-
2:04
two inputs within hours, minutes or even seconds.
-
2:08
A collision is where a different inputs generate the same hash.
-
2:11
Recently, Adobe announced that they had discovered collisions in the also popular
-
2:16
SHA1 hash function.
-
2:17
If you're still using MD5 or SHA1,
-
2:20
update them immediately to a better hash function like SHAKE or Argon2.
-
2:25
So, what if you need to safely store data but also need to be able to read it?
-
2:28
We'll talk about encryption in the next video.
You need to sign up for Treehouse in order to download course files.
Sign up