Generating x_fp_hash using Ocaml

Created by Richard Moore, Modified on Wed, 12 Apr, 2023 at 12:02 PM by Richard Moore

To generate x_fp_hash using Ocaml please see the code below:


(* Requres Ocaml Cryptokit  http://caml.inria.fr/distrib/bazar-ocaml/cryptokit-1.3.tar.gz *)
(* then invoke as 'ocaml unix.cma nums.cma cryptokit.cma  calculate_hash.ml' *)

open Printf;;
open Cryptokit;;

(* HMAC MD5
let calculate_hash hmac_key hmac_data =
  (transform_string (Hexa.encode()) (hash_string (MAC.hmac_md5 hmac_key) hmac_data));;
*)

(* HMAC SHA1 *)
let calculate_hash hmac_key hmac_data =
  (transform_string (Hexa.encode()) (hash_string (MAC.hmac_sha1 hmac_key) hmac_data));;

(* HMAC Key *)
let key = "V0WX5fK~o6eEhr7hbs3ZeyxS";;
let data = Printf.sprintf "%s^%s^%s^%s^%s" "WSP-ACTIV-70" "123" "1228774539" "100.00" "";;

Printf.printf "The data to hash is: %s\n" data;;

Printf.printf "The hash is: %s\n" (calculate_hash key data);;

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article