Problem converting some php code into lucee

Hi,

Anyone knowing php here?
I’m attempting to convert a block of php code into cf, system complained invalid signature, so, something is incorrect, see below, thanks.

 $secret = "fffffffff"; //you number secret
      $timestamp = time();
      $method = "POST";
      $request_path = "/v2/accounts/fffff-fffff-ffff-ffff-ffff/transactions"; //you account id
  
        $data = array (
        'type' => 'send',
        'to' => 'abcPQiuaHmEXRzaG9S1aVJZwHbGYmEs...',
        'amount' => '0.00001'), 
        'currency' => 'XYZ', 
        'description' => 'send you some XYZ', 
        );
        $body = json_encode($data);
        $prehash = $timestamp.$method.$request_path.$body;
        $sign = hash_hmac("sha256", $prehash, $secret);

cf conversion below:

    <cfset secret = "fffffffff">
    <cfset theDate = now()>
    <cfset timestamp = DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), TheDate)>
    <cfset method = "POST">
    <cfset request_path = "/v2/accounts/fffff-fffff-ffff-ffff-ffff/transactions">
    
    <cfset data = ['type':'send','to':'abcPQiuaHmEXRzaG9S1aVJZwHbGYmEs...','amount':'0.00001','currency':'XYZ','description':'send you some XYZ']>
    <cfset body = SerializeJSON(data)>
    <cfset prehash = "#timestamp##method##request_path##body#">
    <cfset sign = HMAC(prehash,secret,"HmacSHA256")>

From a quick look ( I am on mobile) this looks like it’s creating a JWT. I think you just need to implement that (https://jwt.io/ )

There are some cfml libs out there (I know Matt Gifford made one)

HTH.

Mark Drew

1 Like

the php conversion into lucee issue has been resolved, thank you tho.