HMAC explained | keyed hash message authentication code

Поділитися
Вставка
  • Опубліковано 8 жов 2024
  • 🔥More exclusive content: productioncode...
    Twitter: / _jgoebel
    Blog: productioncode...
    Website: jangoebel.com
    In this video we cover what HMAC (keyed hash message authentication code) is and where it is used in the IT world. We also clarify the HMAC vs hash question and explain the two guarantees HMAC gives. HMAC provides integrity and authentication and is often used in JSON Web Tokens with the HS256 algorithm. To understand HMAC you need to understand what a hash function is. A hash function maps an arbitrary amount of input bits to an output bit vector of fixed length.
    With HMAC you can use an arbitrary hashing function such as SHA256 and a secret.

КОМЕНТАРІ • 146

  • @jgoebel
    @jgoebel  3 роки тому +44

    What do you think about this video?
    Was the explanation about HMAC clear?

  • @waelaltaqi
    @waelaltaqi 3 роки тому +4

    Solid vid on hashing and HMAC ... one of the best vids I've seen on the topic period. Thanks!

  • @akhileshgupta5713
    @akhileshgupta5713 3 роки тому +9

    Thanks for a simple and clear explanation!
    here is a question I have, would appreciate your response:
    HMAC looks quite similar to a signed data. only difference i see is with signed data hash is encrypted by a ASYM private key and in HMAC there is rather a secret key known to both parties used!

    • @jgoebel
      @jgoebel  3 роки тому

      Hi Akhilesh, yes that is pretty much the main difference.

  • @MrJohn360
    @MrJohn360 3 роки тому +11

    This was really helpful. The explanation was clear and concyse. Thank you

    • @jgoebel
      @jgoebel  3 роки тому

      thx Jaime I'm glad it was helpful!

  • @AlHoussem
    @AlHoussem Місяць тому +2

    Well explained and good presentation, Thanks

  • @captainnemonic
    @captainnemonic Рік тому

    Clear as newly Windexed glass! I found this helpful. Thanks for putting this out there.

  • @romankovrigin240
    @romankovrigin240 7 місяців тому

    The best explanation I have seen so far, thank you!

    • @jgoebel
      @jgoebel  7 місяців тому

      Glad it was helpful!

  • @message59
    @message59 2 роки тому

    the best explanation that I could find & way better than in my script
    thank you for the effort :)

    • @jgoebel
      @jgoebel  2 роки тому

      Glad it helped!

  • @thornwebdesign
    @thornwebdesign Рік тому +1

    Very good explanation, well done.

    • @jgoebel
      @jgoebel  Рік тому

      Glad you liked it!

  • @binr_9817
    @binr_9817 3 роки тому

    Explanation made sense Helped me to undersand HMAC better Thank your for the Tutorial

    • @jgoebel
      @jgoebel  3 роки тому

      you're welcome Shan 👍

  • @gonzalocruz6653
    @gonzalocruz6653 2 роки тому +4

    It was a very good brief explanaition of HMAC fairly helpfull. I was wondering what is the minimum key size that can be used for HMAC and that is considered secure and not broken?

  • @aghiadalzein3069
    @aghiadalzein3069 4 місяці тому

    Great video ,simple and directly into the point thanks a lot.

    • @jgoebel
      @jgoebel  4 місяці тому

      Glad it was helpful!

  • @siddharthjain3592
    @siddharthjain3592 2 роки тому +3

    This is very helpful. I have a rudimentary question. The difference between the Hash function and HMAC is the secret. The output for both is fixed. Then in the example what additional security does that key provide. Because is HMAC is changed when Hello World changes to Hello Bob. Won't also the Hash function output change in that case? And even then Bob would know that the message has been tampered with. Additionally, in case of HMAC when Bob gets the hacked message, is he also getting the HMAC output , which I am assuming is not tampered, to compare it against his own calculation of HMAC?

    • @rajaaekant
      @rajaaekant Рік тому

      I have the same question and to be honest it seems no different than a JWT

    • @1337soundeZ
      @1337soundeZ Рік тому

      A MiTM could intercept and change the message and then hash it again and attach the new hash together and bob wont notice any changes

    • @1337soundeZ
      @1337soundeZ Рік тому

      @@rajaaekant A MiTM could intercept and change the message and then hash it again and attach the new hash together and bob wont notice any changes

    • @dougsaylor6442
      @dougsaylor6442 7 місяців тому

      For HMAC to work, the key must be secret, and only known by senders and receivers. If this is the case, then MITM is ineffective, because the attacker presumably doesn't have the key. This means that if the message and/or hash is tampered with, then the hash won't match.

  • @maciejwodecki9294
    @maciejwodecki9294 2 роки тому

    Thanks man. Very clear explanation. This is what I was looking for.

    • @jgoebel
      @jgoebel  2 роки тому

      Glad it helped

  • @Alex-nq7uh
    @Alex-nq7uh Рік тому

    Useful explanation- thank you very much

  • @hemantmadan8110
    @hemantmadan8110 3 роки тому +1

    very clear and very precise...really liked it!!

    • @jgoebel
      @jgoebel  3 роки тому

      thx Hemant 👍

  • @ABLyonary
    @ABLyonary 2 роки тому +1

    Great explanation but sometime I notice in these videos is that no actual practical examples are shown. It would be cool to actually see it in action

    • @jgoebel
      @jgoebel  2 роки тому

      thx, I saw in my analytics that people hop off after a short period of time. That's why I thought I keep the video as short as possible

  • @ouss0539
    @ouss0539 6 місяців тому

    best of best explanation ever

  • @or1equalsto1
    @or1equalsto1 7 місяців тому

    Brilliantly explained cheers bro 👊

    • @jgoebel
      @jgoebel  7 місяців тому

      Glad it helped

  • @KirkRivkin
    @KirkRivkin 2 місяці тому

    Excellent explanation, thank you!

    • @jgoebel
      @jgoebel  2 місяці тому

      Glad you enjoyed it!

  • @kebman
    @kebman 2 роки тому

    A great example is when you want to prevent replay attacks. JWT provides some of the same features.

  • @sezgingurel3942
    @sezgingurel3942 Рік тому

    Das war eine tolle Erklärung.

  • @josephnour6888
    @josephnour6888 2 роки тому

    thank you so mush for you help. keep going don't stop

    • @jgoebel
      @jgoebel  2 роки тому

      thx, I'm glad you found it useful

  • @FrankGraffagnino
    @FrankGraffagnino 2 роки тому +1

    question... the HMAC is supposed to provide authentication (meaning know "who" sent the message). But if someone is listening to the messages, couldn't they replay that message from anywhere and make it look like it came from Alice?

    • @jgoebel
      @jgoebel  2 роки тому +1

      Hi Frank, just HMACing the message would indeed not protect against replay attacks. Theoretically you could protect against replay attacks by including the MAC or the previous message in the current message and then HMACing this (crypto.stackexchange.com/questions/39640/can-i-use-a-hmac-for-replay-attack-protection)
      Another option would be to just work with idempotency keys in each message so replaying is essentially useless

  • @hfasihi
    @hfasihi 6 місяців тому

    Well done. Good explanation

    • @jgoebel
      @jgoebel  6 місяців тому

      Glad it was helpful!

  • @ricp
    @ricp Рік тому

    Great explanation, to the point. Thanks

  • @janithmalinga5765
    @janithmalinga5765 2 роки тому

    This is really good explanation, Thanks

    • @jgoebel
      @jgoebel  2 роки тому

      you're most welcome

  • @shakirel
    @shakirel 2 роки тому

    Thank you for this explantion.

    • @jgoebel
      @jgoebel  2 роки тому

      Glad it was helpful!

  • @WildMemo
    @WildMemo 6 місяців тому

    Explained well! Thank you.

    • @jgoebel
      @jgoebel  6 місяців тому

      Glad you liked it

  • @mohamedishhaq9197
    @mohamedishhaq9197 3 роки тому

    Very clear Explanation

    • @jgoebel
      @jgoebel  3 роки тому

      thx Mohamed 👍

  • @ylazerson
    @ylazerson 8 місяців тому

    fantastic video - thanks!

    • @jgoebel
      @jgoebel  8 місяців тому

      Glad it helped!

  • @hugo565
    @hugo565 2 роки тому

    Very nice explanation, thanks !

    • @jgoebel
      @jgoebel  2 роки тому

      Glad it was helpful!

  • @michaelulloa12
    @michaelulloa12 3 роки тому

    Exactly what I was looking for, thank you!

    • @jgoebel
      @jgoebel  3 роки тому

      thx Michael 👍

  • @tuxieo
    @tuxieo 11 місяців тому

    thank you for helping me understand it. it made zero sense when I read about it in class

  • @RandomAlias1
    @RandomAlias1 2 роки тому

    well deserved subscribe.. Great explanation. Well done sir

  • @ferbe666
    @ferbe666 Рік тому

    Really good explanation. So the MAC function, is the same as the HMAC function but without the "Hash function" input, right?

    • @jgoebel
      @jgoebel  Рік тому

      No, HMAC is a subtype of a MAC. There are also other MACs that are not based on hashes, e.g. CMAC or Poly1305

    • @ferbe666
      @ferbe666 Рік тому

      @@jgoebel yes thats what i meant. HMAC is a version of MAC which adds the input "hash function"

    • @jgoebel
      @jgoebel  Рік тому

      @@ferbe666 ah sry, I didn't get it at first what you meant

  • @munidinesh9775
    @munidinesh9775 2 роки тому

    thanks that was helpful, but am sorry, a random doubt why is it always bob and alice
    ?

    • @jgoebel
      @jgoebel  2 роки тому

      A few people came up with the names and people have been using it ever since. How can Alice send a message to Bob is a little bit less abstract than "how can person A send a message to person B". It's sort of similar to "Hello World" examples in programming languages: en.wikipedia.org/wiki/Alice_and_Bob

  • @fgh7832
    @fgh7832 3 роки тому

    This makes sense and assisted me in my research

    • @fgh7832
      @fgh7832 3 роки тому

      Thanks!

    • @jgoebel
      @jgoebel  3 роки тому

      you're most welcome 👍

  • @champsurapong2694
    @champsurapong2694 3 роки тому

    Excellent, ez to understand

    • @jgoebel
      @jgoebel  3 роки тому

      thx Champ 👍

  • @nicetomeetugaming7024
    @nicetomeetugaming7024 2 роки тому

    Thanks, this was really helpful.

    • @jgoebel
      @jgoebel  2 роки тому

      I'm glad it helped

  • @northmania5332
    @northmania5332 2 роки тому

    Thank you for the video! Does HMAC take part in TLS/SSL? When the client and the server pass the TLS handshake and create a common SESSION key, do they also HMAC is message that is being sent out for data integrity?

    • @jgoebel
      @jgoebel  2 роки тому

      No with TLS you use asymmetric cryptography. HMAC would not be suited for this because it requires a shared secret.

    • @northmania5332
      @northmania5332 2 роки тому

      @@jgoebel TLS uses both asymmetric and symmetric cryptography. After they exchange public keys, server or client/(depending on the TLS version), for TLS 1.3 after it receives the TLS ClientHello request the server creates a new session key, and it encryprts it with the public key of the client, send it back to the client, and decrypts it with its private key. Now both have a common SESSION Key, and the encryption becomes symmetric. HMAC is added to each message to keep data integrity with the common key.

  • @gabrielgenao5583
    @gabrielgenao5583 2 роки тому

    Really good video man. But i came with a doubt. How does the two parties agree on having "this secret key"? how is it exchanged? How do i know that the attacker didn't captured the secret key? Thanks!

    • @jgoebel
      @jgoebel  2 роки тому +3

      you would need to exchange the key on a secure channel before. Having shared secrets implies the need for exchanging the secrets before. This is problematic when it comes to data breaches and it is more annoying because you typically do it manually. That's why these days you typically rely on asymmetric cryptography where you only need the public key to verify the signature and where you can easily expose your public key (e.g. by using a JWKS on your server)

  • @dmha1655
    @dmha1655 2 роки тому

    It did make sense - thank you

  • @peter9910
    @peter9910 Рік тому

    How do I do the SHA512 HMAC recursively? i.e.does the key stay the same?

  • @amritadhikari1188
    @amritadhikari1188 2 роки тому

    This is Awesome. Any resources to implementation with JWT?

    • @jgoebel
      @jgoebel  2 роки тому

      this is a good start: github.com/panva/jose

  • @silas3463
    @silas3463 2 роки тому

    This made sense, thanks!

  • @adrianweder7086
    @adrianweder7086 2 роки тому

    old one, but still makes sense! :) zhx!

    • @jgoebel
      @jgoebel  2 роки тому

      HMAC never gets old :)

  • @vadimsadykov8042
    @vadimsadykov8042 Рік тому

    Great explanation

    • @jgoebel
      @jgoebel  Рік тому +1

      Glad it was helpful!

  • @liecretsev
    @liecretsev 3 роки тому

    How do you pass a shared secret key over the network? Is it safe enough to put it inside custom header?

    • @jgoebel
      @jgoebel  3 роки тому

      you would need to share the secret upfront with the other party manually. For security reasons, you cannot send it in the request itself

  • @Kakapo66
    @Kakapo66 2 роки тому

    Good explanation, helped a lot, thanks!

    • @jgoebel
      @jgoebel  2 роки тому

      Glad it helped!

  • @nguyenquan4836
    @nguyenquan4836 Рік тому

    Thank you!!

  • @hypebeastuchiha9229
    @hypebeastuchiha9229 2 роки тому

    That was great
    Thanks for the video

    • @jgoebel
      @jgoebel  2 роки тому

      Glad you enjoyed it

  • @truonghoangha5907
    @truonghoangha5907 2 роки тому

    Can you explain about Secure Remote Password protocal?

  • @KrisMeister
    @KrisMeister Рік тому

    I'm interested in hmac for cloud architecture, so internal http api calls can be verified who sent it and the payload was not modified.
    If you could describe in a part two, the actual oath recomendation for hmac for parakeet and payload validation that would be really cool.

    • @jgoebel
      @jgoebel  Рік тому

      For security reasons, I would recommend to use digital signature schemes instead of HMAC to avoid having shared secrets

  • @sreesha445
    @sreesha445 2 роки тому

    Thanks. Clearly understood.

    • @jgoebel
      @jgoebel  2 роки тому

      Great to hear!

  • @amandaahringer7466
    @amandaahringer7466 3 роки тому

    Great video, thank you!

    • @jgoebel
      @jgoebel  3 роки тому

      thx Amanda, I'm glad you liked it!

  • @majdirekik7549
    @majdirekik7549 Рік тому

    Well done

  • @chillkun713
    @chillkun713 День тому

    Could you tell me about Hmackey

  • @adnantatlis3225
    @adnantatlis3225 2 роки тому

    H(M) is the SHA-256 hash...
    of the message (M)
    what dose mean of the massage here can u explaine ?
    i dont now what is massge mean

    • @jgoebel
      @jgoebel  2 роки тому

      message is whatever you want to hash

  • @deanwhite8413
    @deanwhite8413 Рік тому

    Cool video.

  • @artsofsenthu
    @artsofsenthu 3 роки тому

    Keep up the good work

    • @jgoebel
      @jgoebel  3 роки тому

      thx Senthu 👍

  • @srinivas1483
    @srinivas1483 5 місяців тому

    Message digest algorithms don't use secret keys, where HMAC is a combination of a secret key and a hash function.

  • @ibroschool
    @ibroschool 3 роки тому

    exactly wat i needed

  • @_yak
    @_yak 3 роки тому

    Really clear and easy to follow, thanks!

  • @rukshanaaly7794
    @rukshanaaly7794 2 роки тому

    How does the sender share the key with the recipient?

    • @jgoebel
      @jgoebel  2 роки тому +1

      that would be a manual operation

  • @onlymetalks
    @onlymetalks Рік тому

    The ques is how to get it

  • @jayeshpobari6565
    @jayeshpobari6565 Рік тому

    you can provide this ppt ?

  • @TheBroadwood
    @TheBroadwood 2 роки тому

    So short: a HMAC is an encrypted hash?

    • @jgoebel
      @jgoebel  2 роки тому

      no, an HMAC uses a hash function and a secret to produce a small piece of data called a message authentication code. The message authentication code is created by combining the hash function and the secret. So the MAC is not sth encrypted that you could theoretically decrypt.

  • @zef3589
    @zef3589 Рік тому

    он у папича дома сидит? great explanation btw

  • @PuneetGurtoo
    @PuneetGurtoo 9 місяців тому

    AB De Villiers

  • @nigesp
    @nigesp 2 роки тому

    Thank you for a great explanation.

    • @jgoebel
      @jgoebel  2 роки тому

      Glad you liked it

  • @LewisMoten
    @LewisMoten 3 місяці тому

    How is this different from hashing passwords with salt? hash('sha256', 'My Password'.$salt)