Created
December 2, 2022 17:11
-
-
Save sopanatx/abda63a206de0f95d4e065dc3b62bcf5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getHMacSign(str, str2) | |
implicit none | |
character(len=*), intent(in) :: str, str2 | |
character(len=128) :: result | |
integer :: i, j | |
character(len=8), parameter :: algorithm = "HmacSHA1" | |
character(len=64) :: secret_key = "10f29ff413c89c8de02349cb3eb9a5f510f29ff413c89c8de02349cb3eb9a5f5" | |
character(len=32) :: mac_bytes(16) | |
integer :: mac_bytes_len | |
! Initialize the MAC instance | |
call init_mac(algorithm, secret_key, mac_bytes, mac_bytes_len) | |
! Compute the HMAC signature | |
call compute_hmac_signature("POST", str, "data=" // str2 // "&sid=miui_sec_android", mac_bytes, mac_bytes_len) | |
! Convert the signature bytes to a hexadecimal string | |
do i = 1, mac_bytes_len | |
call byte_to_hex(mac_bytes(i), result(2 * i - 1:2 * i)) | |
end do | |
! Return the result as a lowercase string | |
do j = 1, len(result) | |
result(j:j) = tolower(result(j:j)) | |
end do | |
getHMacSign = result | |
end function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment