Guest User

signUrl.php

a guest
May 9th, 2022
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. $key = '943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881';
  4. $salt = '520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5';
  5. //this function taking hexa key and converting it into binary string
  6. $keyBin = pack("H*" , $key);
  7.  
  8. if(empty($keyBin)) {
  9. die('Key expected to be hex-encoded string');
  10. }
  11.  
  12. $saltBin = pack("H*" , $salt);
  13. if(empty($saltBin)) {
  14. die('Salt expected to be hex-encoded string');
  15. }
  16.  
  17. // print_r($saltBin);
  18. // exit;
  19.  
  20. $resize = 'fill';
  21. $width = 300;
  22. $height = 300;
  23. $gravity = 'no';
  24. $enlarge = 1;
  25. $extension = 'png';
  26.  
  27. $url = 'http://img.example.com/pretty/image.jpg';
  28. $encodedUrl = rtrim(strtr(base64_encode($url), '+/', '-_'), '=');
  29.  
  30. $path = "/rs:{$resize}:{$width}:{$height}:{$enlarge}/g:{$gravity}/{$encodedUrl}.{$extension}";
  31.  
  32. // echo $keyBin;
  33. // exit;
  34.  
  35. echo hash_hmac('sha256', $saltBin.$path, $keyBin);
  36. exit;
  37.  
  38. $signature = rtrim(strtr(base64_encode(hash_hmac('sha256', $saltBin.$path, $keyBin, true)), '+/', '-_'), '=');
  39.  
  40. print(sprintf("/%s%s", $signature, $path));
  41.  
Add Comment
Please, Sign In to add comment