What is Hashing?
Hashing is the process of transforming any given key or a string of characters into another value. This is usually represented by a shorter, fixed-length value or key that represents and makes it easier to find or employ the original string.
The most popular use for hashing is the implementation of hash tables. A hash table stores key and value pairs in a list accessible through its index. Because key and value pairs are unlimited, the hash function will map the keys to the table size. A hash value then becomes the index for a specific element.
A hash function generates new values according to a mathematical hashing algorithm, known as a hash value or simply a hash. To prevent hash conversion back into the original key, a good hash always uses a one-way hashing algorithm.
Hashing is relevant to — but is not limited to — data indexing and retrieval, digital signatures, cybersecurity, and cryptography.
What is hashing used for?
- Data Retrieval
- Digital Signatures
- etc
Hashing uses functions or algorithms to map object data to a representative integer value. A hash can then be used to narrow down searches when locating these items on that object data map.
For example, in hash tables, developers store data — perhaps a customer record — in the form of key and value pairs. The key helps identify the data and operates as an input to the hashing function, while the hash code or the integer is then mapped to a fixed size.
Hash tables support functions that include the following:
- insert (key, value)
- get (key)
- delete (key)
In addition to enabling rapid data retrieval, hashing helps encrypt and decrypt digital signatures used to authenticate message senders and receivers. In this scenario, a hash function transforms the digital signature before both the hashed value (known as a message digest) and the signature are sent in separate transmissions to the receiver.
Types Of Hash Algo
Cryptography uses multiple hash functions to secure data. Some of the most popular cryptographic hashes include the following:
- Secure Hash Algorithm 1 (SHA-1)
- Secure Hash Algorithm 2 (SHA-2)
- Secure Hash Algorithm 3 (SHA-3)
- MD2
- MD4
- MD5
As shown above create a function to create a hash
Then,
OUTPUT := b10a8db164e0754105b7a99be72e3fe5
package mainimport (
"crypto/md5"
"encoding/hex"
"io"
)func CreateMd5Hash(text string) string {
hasher := md5.New()
_, err := io.WriteString(hasher, text)
if err != nil {
panic(err)
}return hex.EncodeToString(hasher.Sum(nil))
}func main() {
println(CreateMd5Hash("Hello World"))
}
If you found this helpful, make sure to show your support with a clap, and if you want to help others in their projects, a share would be greatly appreciated! Let me know what you think about this! Happy Learning Hashing!