Advertisement
Guest User

ColdFusion Base64 helper functions

a guest
Feb 4th, 2011
1,623
0
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>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement