write a code python to compute the hMAC i need the user to write the input Example 2: key length = block size Input data:Message: “Hello” → x48656C6C 6FSecret Key: “4q72JHgX89z3BkFMt6cwQxL1rD28jpN5UfVhIZYPbCSeuGovRaWmA0sD9ECtX7Jf” → x34713732 4A486758 38397A33 426B464D 74366377 51784C31 72443238 6A704E35 55665668 495A5950 62435365 75476F76 5261576D 41307344 39454374 58374A66 Constants for our case hash algorithm (SHA1) with block size 64 bytes:ipad (in HEX): x36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 (x36 repeated 64 time)opad (in HEX): x5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C (x5C repeated 64 time) Steps of creating HMAC (you could use the calculator to verify the result): If the key length = block size, then we do nothing. In our case, with a key length of 64 bytes, we proceed with no additional action.So new key is K0 = 34713732 4A486758 38397A33 426B464D 74366377 51784C31 72443238 6A704E35 55665668 495A5950 62435365 75476F76 5261576D 41307344 39454374 58374A66 We need to perform the operation K0 XOR ipad.How to make XOR operation you can see hereor use the calculator.K0 XOR ipad = 02470104 7C7E516E 0E0F4C05 745D707B 42005541 674E7A07 4472040E 5C467803 6350605E 7F6C6F66 54756553 43715940 6457615B 77064572 0F737542 6E017C50 Now, append the message (K0 XOR ipad || message) to K0 XOR ipad.(K0 XOR ipad) || message = 02470104 7C7E516E 0E0F4C05 745D707B 42005541 674E7A07 4472040E 5C467803 6350605E 7F6C6F66 54756553 43715940 6457615B 77064572 0F737542 6E017C50 48656C6C 6F We put the result of the previous operation into the SHA-1 hash.Please note that you need to specify to the calculator that your data is in HEX (use this calculator). Also, you should remove all spaces (remember spaces are added here for readability but should not be included when hashing). In other words, you should input into the hash function: 024701047C7E516E0E0F4C05745D707B42005541674E7A074472040E5C4678036350605E7F6C6F6654756553437159406457615B770645720F7375426E017C5048656C6C6Fsha1(K0 XOR ipad || message) =5fa962fde86832f2d5935b8be0229987e510f99f Perform the operation K0 XOR opad.K0 XOR opad = 682D6B6E 16143B04 6465266F 1E371A11 286A3F2B 0D24106D 2E186E64 362C1269 093A0A34 1506050C 3E1F0F39 291B332A 0E3D0B31 1D6C2F18 65191F28 046B163A Append to the result of the previous operation the wich hash obtained in step 4.(K0 XOR opad) || (sha1(K0 XOR ipad || message)) = 682D6B6E 16143B04 6465266F 1E371A11 286A3F2B 0D24106D 2E186E64 362C1269 093A0A34 1506050C 3E1F0F39 291B332A 0E3D0B31 1D6C2F18 65191F28 046B163A 5FA962FD E86832F2 D5935B8B E0229987 E510F99F Put the result of step 6 into the SHA-1 hash.HMAC = 62e1eaf2a7075bceb8e0022ae7d3e3d6f7271609
write a code python to compute the hMAC
i need the user to write the input
Example 2: key length = block size
Input data:
Message: “Hello” → x48656C6C 6F
Secret Key: “4q72JHgX89z3BkFMt6cwQxL1rD28jpN5UfVhIZYPbCSeuGovRaWmA0sD9ECtX7Jf” → x34713732 4A486758 38397A33 426B464D 74366377 51784C31 72443238 6A704E35 55665668 495A5950 62435365 75476F76 5261576D 41307344 39454374 58374A66
Constants for our case hash algorithm (SHA1) with block size 64 bytes:
ipad (in HEX): x36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 (x36 repeated 64 time)
opad (in HEX): x5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C (x5C repeated 64 time)
Steps of creating HMAC (you could use the calculator to verify the result):
- If the key length = block size, then we do nothing. In our case, with a key length of 64 bytes, we proceed with no additional action.
So new key is K0 = 34713732 4A486758 38397A33 426B464D 74366377 51784C31 72443238 6A704E35 55665668 495A5950 62435365 75476F76 5261576D 41307344 39454374 58374A66 - We need to perform the operation K0 XOR ipad.
How to make XOR operation you can see hereor use the calculator.
K0 XOR ipad = 02470104 7C7E516E 0E0F4C05 745D707B 42005541 674E7A07 4472040E 5C467803 6350605E 7F6C6F66 54756553 43715940 6457615B 77064572 0F737542 6E017C50 - Now, append the message (K0 XOR ipad || message) to K0 XOR ipad.
(K0 XOR ipad) || message = 02470104 7C7E516E 0E0F4C05 745D707B 42005541 674E7A07 4472040E 5C467803 6350605E 7F6C6F66 54756553 43715940 6457615B 77064572 0F737542 6E017C50 48656C6C 6F - We put the result of the previous operation into the SHA-1 hash.
Please note that you need to specify to the calculator that your data is in HEX (use this calculator). Also, you should remove all spaces (remember spaces are added here for readability but should not be included when hashing). In other words, you should input into the hash function: 024701047C7E516E0E0F4C05745D707B42005541674E7A074472040E5C4678036350605E7F6C6F6654756553437159406457615B770645720F7375426E017C5048656C6C6F
sha1(K0 XOR ipad || message) =
5fa962fde86832f2d5935b8be0229987e510f99f - Perform the operation K0 XOR opad.
K0 XOR opad = 682D6B6E 16143B04 6465266F 1E371A11 286A3F2B 0D24106D 2E186E64 362C1269 093A0A34 1506050C 3E1F0F39 291B332A 0E3D0B31 1D6C2F18 65191F28 046B163A - Append to the result of the previous operation the wich hash obtained in step 4.
(K0 XOR opad) || (sha1(K0 XOR ipad || message)) = 682D6B6E 16143B04 6465266F 1E371A11 286A3F2B 0D24106D 2E186E64 362C1269 093A0A34 1506050C 3E1F0F39 291B332A 0E3D0B31 1D6C2F18 65191F28 046B163A 5FA962FD E86832F2 D5935B8B E0229987 E510F99F - Put the result of step 6 into the SHA-1 hash.
HMAC = 62e1eaf2a7075bceb8e0022ae7d3e3d6f7271609
Unlock instant AI solutions
Tap the button
to generate a solution