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);;
0 Comments