E-xact Knowledge Base

Sample code for generating the hash for Hosted Checkout using Ocaml

To generate x_fp_hash using Ocaml, please see the snippet 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);;

-----------------------------------------------------------------------------------------------


Article Details

Last Updated
20th of May, 2010

Would you like to...

Print this page Print this page

Email this page Email this page

Post a comment Post a comment

Subscribe me

Add to favorites Add to favorites

Remove Highlighting Remove Highlighting

Edit this Article

Quick Edit

Export to PDF

User Opinions (0 votes)

No users have voted.

How would you rate this answer?



Thank you for rating this answer.

Related Articles

No related articles were found.

Attachments

No attachments were found.

Continue