Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

ColdFusion Base64 helper functions

By: a guest on Feb 4th, 2011  |  syntax: ColdFusion  |  size: 1.58 KB  |  views: 469  |  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. <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>