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
163
votes
11 answers

How to hash a password

I'd like to store the hash of a password on the phone, but I'm not sure how to do it. I can only seem to find encryption methods. How should the password be hashed properly?
Skoder
  • 3,983
  • 11
  • 46
  • 73
163
votes
22 answers

Removing all empty elements from a hash / YAML?

How would I go about removing all empty elements (empty list items) from a nested Hash or YAML file?
Brian Jordan
  • 2,377
  • 3
  • 21
  • 29
162
votes
7 answers

Storing SHA1 hash values in MySQL

I have a simple question which occured when I wanted to store the result of a SHA1 hash in a MySQL database: How long should the VARCHAR field be in which I store the hash's result?
niklasfi
  • 15,245
  • 7
  • 40
  • 54
160
votes
9 answers

Difference between Hashing a Password and Encrypting it

The current top-voted to this question states: Another one that's not so much a security issue, although it is security-related, is complete and abject failure to grok the difference between hashing a password and encrypting it. Most commonly found…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
159
votes
5 answers

Mismatch Detected for 'RuntimeLibrary'

I downloaded and extracted Crypto++ in C:\cryptopp. I used Visual Studio Express 2012 to build all the projects inside (as instructed in readme), and everything was built successfully. Then I made a test project in some other folder and added…
Momonga
  • 1,843
  • 2
  • 15
  • 13
158
votes
17 answers

php mysqli_connect: authentication method unknown to the client [caching_sha2_password]

I am using php mysqli_connect for login to a MySQL database (all on localhost)
Guti_Haz
  • 2,528
  • 2
  • 15
  • 20
157
votes
15 answers

Best way to generate random file names in Python

In Python, what is a good, or the best way to generate some random text to prepend to a file(name) that I'm saving to a server, just to make sure it does not overwrite. Thank you!
zallarak
  • 5,287
  • 7
  • 38
  • 54
156
votes
9 answers

Is MD5 still good enough to uniquely identify files?

Is MD5 hashing a file still considered a good enough method to uniquely identify it given all the breaking of MD5 algorithm and security issues etc? Security is not my primary concern here, but uniquely identifying each file is. Any thoughts?
Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
155
votes
7 answers

Is SHA-1 secure for password storage?

Conclusion: SHA-1 is safe against preimage attacks, however it is easy to compute, which means it is easier to mount a bruteforce or dictionary attack. (The same is true for successors like SHA-256.) Depending on the circumstances, a hash function…
Tgr
  • 27,442
  • 12
  • 81
  • 118
151
votes
9 answers

Which cryptographic hash function should I choose?

The .NET framework ships with 6 different hashing algorithms: MD5: 16 bytes (Time to hash 500MB: 1462 ms) SHA-1: 20 bytes (1644 ms) SHA256: 32 bytes (5618 ms) SHA384: 48 bytes (3839 ms) SHA512: 64 bytes (3820 ms) RIPEMD: 20 bytes (7066 ms) Each of…
Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
148
votes
20 answers

Linux: compute a single hash for a given folder & contents?

Surely there must be a way to do this easily! I've tried the Linux command-line apps such as sha1sum and md5sum but they seem only to be able to compute hashes of individual files and output a list of hash values, one for each file. I need to…
Ben L
  • 6,618
  • 8
  • 39
  • 34
147
votes
14 answers

When is CRC more appropriate to use than MD5/SHA1?

When is it appropriate to use CRC for error detection versus more modern hashing functions such as MD5 or SHA1? Is the former easier to implement on embedded hardware?
Gili
  • 86,244
  • 97
  • 390
  • 689
147
votes
6 answers

Ruby Hash to array of values

I have this: hash = { "a"=>["a", "b", "c"], "b"=>["b", "c"] } and I want to get to this: [["a","b","c"],["b","c"]] This seems like it should work but it doesn't: hash.each{|key,value| value} => {"a"=>["a", "b", "c"], "b"=>["b", "c"]} Any…
tbrooke
  • 2,137
  • 2
  • 17
  • 25
147
votes
9 answers

What is a good Hash Function?

What is a good Hash function? I saw a lot of hash function and applications in my data structures courses in college, but I mostly got that it's pretty hard to make a good hash function. As a rule of thumb to avoid collisions my professor said…
Hoffmann
  • 14,369
  • 16
  • 76
  • 91
146
votes
7 answers

Is calculating an MD5 hash less CPU intensive than SHA family functions?

Is calculating an MD5 hash less CPU intensive than SHA-1 or SHA-2 on "standard" laptop x86 hardware? I'm interested in general information, not specific to a certain chip. UPDATE: In my case, I'm interested in calculating the hash of a file. If…
Mick
  • 13,248
  • 9
  • 69
  • 119