Guest User

Coldfusion

a guest
May 9th, 2022
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <cfset key = '943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881'>
  2. <cfset salt = '520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5'>
  3.  
  4. <!--- converting hexa to binary --->
  5. <cfset keyBin = #binaryDecode(key, 'hex')#>
  6.  
  7. <!--- converting binary to string--->
  8. <cfset keyBin = #toString(keyBin)#>
  9.  
  10. <cfif NOT isDefined("keyBin")>
  11. <cfabort showError = "Key expected to be hex-encoded string">
  12. </cfif>
  13.  
  14. <!--- converting hexa to binary --->
  15. <cfset saltBin = #binaryDecode(salt, 'hex')#>
  16.  
  17. <!--- converting binary to string--->
  18. <cfset saltBin = #toString(saltBin)#>
  19.  
  20. <!--- <cfdump var="#saltBin#"> --->
  21.  
  22. <cfif NOT isDefined("saltBin")>
  23. <cfabort showError = "Salt expected to be hex-encoded string">
  24. </cfif>
  25.  
  26. <cfset resize = 'fill'>
  27. <cfset width = '300'>
  28. <cfset height = '300'>
  29. <cfset gravity = 'no'>
  30. <cfset enlarge = 1>
  31. <cfset extension = 'png'>
  32.  
  33. <cfset imgurl = 'http://img.example.com/pretty/image.jpg'>
  34.  
  35. <!--- <cfdump var= #ToBase64(imgurl)#> --->
  36.  
  37. <cfset encoded = ToBase64(imgurl)>
  38.  
  39. <cfset encoded = replaceNoCase(encoded, "+", "-",'ALL')>
  40. <cfset encoded = replaceNoCase(encoded, "/", "_",'ALL')>
  41.  
  42. <cfset encoded = trim(encoded)>
  43.  
  44. <cfif right(encoded, 1) is "=">
  45. <cfset encoded = left(encoded, len(encoded)-1)>
  46. </cfif>
  47.  
  48. <!--- <cfdump var= #encoded#> --->
  49.  
  50. <cfset path = "/rs:"&resize&":"&width&":"&height&":"&enlarge&"/g:"&gravity&"/"&encoded&"."&extension>
  51.  
  52.  
  53. <cfset abc = hmac(saltBin&path,keyBin,"HMACSHA256")>
  54. <cfoutput>#abc#</cfoutput>
  55.  
  56. <!--- <cfoutput>#abc#</cfoutput> --->
  57.  
  58. <!--- <cfoutput>#abc#</cfoutput> --->
  59. <cfabort>
  60.  
  61. <!--- <!--- converting hexa to binary --->
  62. <cfset abc = #binaryDecode(abc, 'hex')#> --->
  63.  
  64.  
  65. <!--- converting binary to string--->
  66. <!--- cfset abc = binaryEncode( binaryDecode(abc, "hex"), "base64" )> --->
  67.  
  68.  
  69.  
  70.  
  71. <!--- <cfoutput>#binaryEncode( binaryDecode(abc, "hex"), "base64" )#</cfoutput> --->
  72.  
  73.  
  74.  
  75.  
  76. <cfabort>
  77.  
  78. <!--- <cfset url = 'http://img.example.com/pretty/image.jpg'>
  79.  
  80. $encodedUrl = rtrim(strtr(base64_encode($url), '+/', '-_'), '='); --->
Add Comment
Please, Sign In to add comment