Fundamental difference between Hashing and Encryption algorithms

前端 未结 13 2055
日久生厌
日久生厌 2020-11-21 06:35

I see a lot of confusion between hashes and encryption algorithms and I would like to hear some more expert advice about:

  1. When to use hashes vs encryptions<

相关标签:
13条回答
  • 2020-11-21 07:16

    Basic overview of hashing and encryption/decryption techniques are.

    Hashing:

    If you hash any plain text again you can not get the same plain text from hashed text. Simply, It's a one-way process.

    hashing


    Encryption and Decryption:

    If you encrypt any plain text with a key again you can get same plain text by doing decryption on encrypted text with same(symetric)/diffrent(asymentric) key.

    encryption and decryption


    UPDATE: To address the points mentioned in the edited question.

    1. When to use hashes vs encryptions

    Hashing is useful if you want to send someone a file. But you are afraid that someone else might intercept the file and change it. So a way that the recipient can make sure that it is the right file is if you post the hash value publicly. That way the recipient can compute the hash value of the file received and check that it matches the hash value.

    Encryption is good if you say have a message to send to someone. You encrypt the message with a key and the recipient decrypts with the same (or maybe even a different) key to get back the original message. credits


    2. What makes a hash or encryption algorithm different (from a theoretical/mathematical level) i.e. what makes hashes irreversible (without aid of a rainbow tree)

    Basically hashing is an operation that loses information but not encryption. Let's look at the difference in simple mathematical way for our easy understanding, of course both have much more complicated mathematical operation with repetitions involved in it

    Encryption/Decryption (Reversible):


    Addition:

    4 + 3 = 7  
    

    This can be reversed by taking the sum and subtracting one of the addends

    7 - 3 = 4     
    

    Multiplication:

    4 * 5 = 20  
    

    This can be reversed by taking the product and dividing by one of the factors

    20 / 4 = 5    
    

    So, here we could assume one of the addends/factors is a decrpytion key and result(7,20) is an excrypted text.


    Hashing (Not Reversible):


    Modulo division:

    22 % 7 = 1   
    

    This can not be reversed because there is no operation that you can do to the quotient and the dividend to reconstitute the divisor (or vice versa).

    Can you find an operation to fill in where the '?' is?

    1  ?  7 = 22  
    1  ?  22 = 7
    

    So hash functions have the same mathematical quality as modulo division and looses the information.

    credits

    0 讨论(0)
提交回复
热议问题