Questions tagged [hash]

A hash function is any well-defined procedure or mathematical function that converts a large amount of data into a small datum, usually a single integer. For questions about hashtags as used to label content on social media, use hashtag. For questions about URLs and HTML anchors, use fragment-identifier. For questions about Ruby's hash type, use ruby-hash.

A is any well-defined procedure or mathematical function that converts a large, possibly variable-sized amount of data into a small datum, usually a single integer that may serve as an index to an array. The values returned by a hash function are called hash values, s, hash sums, checksums or simply hashes. A occurs when two unequal datums generate the same hash code with a particular hash function. This can have various negative effects and good hash functions minimize the number of collisions.

For data structures that make use of hash functions and hashcodes, see , , , , and .

A cryptographically strong hash function has two additional features: it is mathematically proven to be irreversible and minimizes collisions. Irreversibility means that the original data cannot be reconstructed from its hash. For questions specifically about cryptographically secure uses of hash functions, use combined with the tag. Contrast with , which must be reversible.

Hash functions are related to (and often confused with) checksums, check digits, fingerprints, randomization functions, and error-correcting codes. Although these concepts overlap to some extent (some hash functions are specifically designed to also serve as checksums), each has its own uses and requirements and is designed and optimized differently.

For questions about hashtags as used to label and navigate content on social media, use . For questions about URLs and HTML anchors, use . For questions about Ruby's hash type, use .

23903 questions
316
votes
10 answers

What data type to use for hashed password field and what length?

I'm not sure how password hashing works (will be implementing it later), but need to create database schema now. I'm thinking of limiting passwords to 4-20 characters, but as I understand after encrypting hash string will be of different length. So,…
z-boss
  • 17,111
  • 12
  • 49
  • 81
314
votes
10 answers

Why is Git not considered a "block chain"?

Git's internal data structure is a tree of data objects, wherein each objects only points to its predecessor. Each data block is hashed. Modifying (bit error or attack) an intermediate block will be noticed when the saved hash and the actual hash…
Paebbels
  • 15,573
  • 13
  • 70
  • 139
314
votes
5 answers

What is Hash and Range Primary Key?

I am not able to understand what Range / primary key is here in the docs on Working with Tables and Data in DynamoDB How does it work? What do they mean by "unordered hash index on the hash attribute and a sorted range index on the range attribute"?
mannuscript
  • 4,711
  • 6
  • 26
  • 25
300
votes
7 answers

Where do you store your salt strings?

I've always used a proper per-entry salt string when hashing passwords for database storage. For my needs, storing the salt in the DB next to the hashed password has always worked fine. However, some people recommend that the salt be stored…
friedo
  • 65,762
  • 16
  • 114
  • 184
289
votes
24 answers

Is it possible to decrypt MD5 hashes?

Someone told me that he has seen software systems that: retrieve MD5 encrypted passwords from other systems; decrypt the encrypted passwords and store the passwords in the database of the system using the systems own algorithm. Is that possible? I…
John B
  • 20,062
  • 35
  • 120
  • 170
274
votes
4 answers

How do I search within an array of hashes by hash values in ruby?

I have an array of hashes, @fathers. a_father = { "father" => "Bob", "age" => 40 } @fathers << a_father a_father = { "father" => "David", "age" => 32 } @fathers << a_father a_father = { "father" => "Batman", "age" => 50 } @fathers << a_father…
doctororange
  • 11,670
  • 12
  • 42
  • 58
264
votes
3 answers

Is it safe to ignore the possibility of SHA collisions in practice?

Let's say we have a billion unique images, one megabyte each. We calculate the SHA-256 hash for the contents of each file. The possibility of collision depends on: the number of files the size of the single file How far can we go ignoring this…
Hristo Hristov
  • 4,021
  • 4
  • 25
  • 37
259
votes
4 answers

Is a Python dictionary an example of a hash table?

One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hash table? If not, what is it?
Tommy Herbert
  • 20,407
  • 14
  • 52
  • 57
248
votes
13 answers

How can I replace a hash key with another key?

I have a condition that gets a hash. hash = {"_id"=>"4de7140772f8be03da000018", .....} Yet, I want to rename the key of that hash as follows. hash = {"id"=>"4de7140772f8be03da000018", ......} P.S. I don't know what keys are in the hash; they…
Manish Das
  • 3,785
  • 2
  • 21
  • 34
248
votes
10 answers

How does password salt help against a rainbow table attack?

I'm having some trouble understanding the purpose of a salt to a password. It's my understanding that the primary use is to hamper a rainbow table attack. However, the methods I've seen to implement this don't seem to really make the problem…
Rich
  • 12,068
  • 9
  • 62
  • 94
247
votes
3 answers

Why does Python's hash of infinity have the digits of π?

The hash of infinity in Python has digits matching pi: >>> inf = float('inf') >>> hash(inf) 314159 >>> int(math.pi*1e5) 314159 Is that just a coincidence or is it intentional?
wim
  • 338,267
  • 99
  • 616
  • 750
246
votes
13 answers

Fastest hash for non-cryptographic uses?

I'm essentially preparing phrases to be put into the database, they may be malformed so I want to store a short hash of them instead (I will be simply comparing if they exist or not, so hash is ideal). I assume MD5 is fairly slow on 100,000+…
John
  • 3,238
  • 4
  • 22
  • 25
237
votes
4 answers

How do I use Node.js Crypto to create a HMAC-SHA1 hash?

I want to create a hash of I love cupcakes (signed with the key abcdeg) How can I create that hash, using Node.js Crypto?
user847495
  • 9,831
  • 17
  • 45
  • 48
233
votes
5 answers

SHA512 vs. Blowfish and Bcrypt

I'm looking at hashing algorithms, but couldn't find an answer. Bcrypt uses Blowfish Blowfish is better than MD5 Q: but is Blowfish better than SHA512? Thanks.. Update: I want to clarify that I understand the difference between hashing and…
Chris
  • 8,736
  • 18
  • 49
  • 56
232
votes
17 answers

Hashing a dictionary?

For caching purposes I need to generate a cache key from GET arguments which are present in a dict. Currently I'm using sha1(repr(sorted(my_dict.items()))) (sha1() is a convenience method that uses hashlib internally) but I'm curious if there's a…
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636