Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 23rd, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to write a HMAC SHA1 code to compare the check sum generated by a PHP code and JSP code
  2. // Adjust key to exactly 64 bytes
  3.     if (strlen($key) > 64) {
  4.         $key = str_pad(sha1($key, true), 64, chr(0));
  5.     }
  6.     if (strlen($key) < 64) {
  7.         $key = str_pad($key, 64, chr(0));
  8.     }
  9.  
  10.     // Outter and Inner pad
  11.     $opad = str_repeat(chr(0x5C), 64);
  12.     $ipad = str_repeat(chr(0x36), 64);
  13.  
  14.     // Xor key with opad & ipad
  15.     for ($i = 0; $i < strlen($key); $i++) {
  16.         $opad[$i] = $opad[$i] ^ $key[$i];
  17.         $ipad[$i] = $ipad[$i] ^ $key[$i];
  18.     }
  19.  
  20.     return sha1($opad . sha1($ipad . $data, true));
  21. }