Guest User

ColdFusion Base64 helper functions

a guest
Feb 4th, 2011
1,371
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfcomponent displayname="String" output="false" hint="String related functions.">
  2.  
  3.     <cffunction name="init" access="public" output="false" returntype="void">
  4.     </cffunction>
  5.  
  6.     <cffunction name="Base64Encode" access="public" output="false" returntype="string" hint="Returns a Base64 encoded string.">
  7.         <cfargument name="String" type="string" required="true" hint="String to encode.">
  8.  
  9.         <cfreturn BinaryEncode(CharsetDecode(Arguments.String, "utf-8"), "Base64")>
  10.     </cffunction>
  11.  
  12.     <cffunction name="Base64Decode" access="public" output="false" returntype="string" hint="Returns a Base64 decoded string.">
  13.         <cfargument name="String" type="string" required="true" hint="String to decode.">
  14.  
  15.         <cfreturn CharsetEncode(BinaryDecode(Arguments.String, "Base64"), "utf-8")>
  16.     </cffunction>
  17.  
  18.     <cffunction name="Base64URLEncode" access="public" output="false" returntype="string" hint="Returns a base64url encoded string.">
  19.         <cfargument name="String" type="string" required="true" hint="String to encode.">
  20.  
  21.         <cfreturn Replace( Replace( Replace( Variables.Base64Encode(Arguments.String), "=", "", "all"), "+", "-", "all"), "/", "_", "all")>
  22.     </cffunction>
  23.  
  24.     <cffunction name="Base64URLDecode" access="public" output="false" returntype="string" hint="Returns a base64url decoded string.">
  25.         <cfargument name="String" type="string" required="true" hint="String to decode.">
  26.  
  27.         <cfreturn Variables.Base64Decode( Replace( Replace( Arguments.String, "-", "+", "all"), "_", "/", "all") & RepeatString("=", Len(Arguments.String) + (4 - Len(Arguments.String) % 4) % 4))>
  28.     </cffunction>
  29.  
  30. </cfcomponent>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×