<?php
        require_once(get_cfg_var("doc_root") . "/ConnectPHP/Connect_init.php" );
        #Change these values before implmenting.
        try {
          initConnectAPI("<username>", "<passowrd>");
        } catch (Exception $e) {
          alert('Make sure to change the default user/pass')
        }

/***Use the Crypto versioned namespace***/
use RightNow\Connect\v1_4 as RNCPHP;
use RightNow\Connect\Crypto\v1_4 as Crypto;

RNCPHP\ConnectAPI::getCurrentContext()->ApplicationContext = "Crypto sha256 message test";

// HASH 256 functionality
function standard_crypt($msg){
  try{
     $md = new Crypto\MessageDigest();
     $md->Algorithm->ID = 3; //SHA256
     $md->Text = $msg;
     $md->hash();
     $hashed_text = $md->HashText;
     return ($hashed_text);
  } catch (Exception $err ){
       echo $err->getMessage();
  }
}
// Create Signature Hash
function custom_hmac($algo, $data, $key, $raw_output = false)
{
    $size = 64;
    $pack = chr(0x00);
    if (strlen($key) > $size) {
        $key = $algo($key);
    } else {
        $key = $key . str_repeat(chr(0x00), $size - strlen($key));
    }
    // Outter and Inner pad
    $opad = str_repeat(chr(0x5C), $size);
    $ipad = str_repeat(chr(0x36), $size);

    $k_ipad = $ipad ^ $key;
    $k_opad = $opad ^ $key;

    return $algo($k_opad.$algo($k_ipad.$data));
}

$data = "Protected stuff here thats procted";
$secret "Secret";
$bin_hash = custom_hmac('standard_crypt', $data, $secret, false);
echo "HASH: ".bin2hex($bin_hash);
?>
