3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //Enter your code here, enjoy! function hmac($algo,$data,$passwd){ /* md5 and sha1 only */ $algo=strtolower($algo); echo $algo; $p=array('md5'=>'greatherH32','sha1'=>'H40'); if(strlen($passwd)>64) { $passwd=pack($p[$algo],$algo($passwd)); echo 'pass greater than 64'.chr(13); echo $passwd; } if(strlen($passwd)<64) { $passwd=str_pad($passwd,64,chr(0)); echo 'pass smaller than 64'.chr(13); echo $passwd; } $ipad=substr($passwd,0,64) ^ str_repeat(chr(0x36),64); echo 'ipad: '.$ipad.chr(13); $opad=substr($passwd,0,64) ^ str_repeat(chr(0x5C),64); echo 'opad: '.$opad.chr(13); $hashedIpadData =$algo($ipad.$data); $opadPack = $opad.pack($p[$algo],$hashedIpadData); return($algo($opadPack)); } # XXX ePay.bg URL (https://devep2.datamax.bg/ep2/epay2_demo/ if POST to DEMO system) $submit_url = 'https://devep2.datamax.bg/ep2/epay2_demo/'; # XXX Secret word with which merchant make CHECKSUM on the ENCODED packet $secret = 'secret'; $min = 'D544248794'; $invoice = 1234; # XXX Invoice $sum = '22.80'; # XXX Ammount $exp_date = '01.08.2020'; # XXX Expiration date $descr = 'Test'; # XXX Description $data = <<<DATA MIN={$min} INVOICE={$invoice} AMOUNT={$sum} EXP_TIME={$exp_date} DESCR={$descr} DATA; # XXX Packet: # (MIN or EMAIL)= REQUIRED # INVOICE= REQUIRED # AMOUNT= REQUIRED # EXP_TIME= REQUIRED # DESCR= OPTIONAL $ENCODED = base64_encode($data); $CHECKSUM = hmac('sha1', $ENCODED, $secret); # XXX SHA-1 algorithm REQUIRED echo <<<HTML <HTML> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1251"> </head> <BODY TEXT=#000000 BGCOLOR=#FFFFFF> <p>{$ENCODED}</p> <p>{$CHECKSUM}</p> HTML; ?>
Output for 4.3.0 - 7.1.0
sha1pass smaller than 64 secretipad: ESUDSB6666666666666666666666666666666666666666666666666666666666 opad: /9?.9(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ <HTML> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1251"> </head> <BODY TEXT=#000000 BGCOLOR=#FFFFFF> <p>TUlOPUQ1NDQyNDg3OTQKSU5WT0lDRT0xMjM0CkFNT1VOVD0yMi44MApFWFBfVElNRT0wMS4wOC4yMDIwCkRFU0NSPVRlc3Q=</p> <p>6a66f506e98b21038147fe28b77abcfc0bd156b3</p>