ToBase64

Description

Calculates the Base64 representation of a string or binary object. The Base64 format uses printable characters, allowing binary data to be sent in forms and e-mail, and stored in a database or file.

Returns

The Base64 representation of a string or binary object.

Category

Conversion functionsString functions

Function syntax

ToBase64(strOrBin [, encoding])

See also

  • BinaryEncode for conversion of binary data to base64
  • cffile for information about loading and reading binary data
  • cfwddx for information about serializing and deserializing binary data
  • IsBinary and ToBinary for checking for binary data and converting a Base64 object to binary format

History

ColdFusion (2018 release): Introduced named parameters.

ColdFusion MX: Added the encoding parameter.

Parameters

Parameter

Description

strOrBin

A string, the name of a string, or a binary object.

encoding

For a string, defines how characters are represented in a byte array. The following list includes commonly used values:

  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16
    For more information on character encoding, see: http://www.w3.org/International/O-charset.en.html. The default value is the encoding of the page on which the function is called. See cfcontent. For a binary object, this parameter is ignored.

Usage

Adobe recommends that you use the BinaryEncode function to convert binary data to Base64-encoded data in all new applications.

<cfscript>
    myid="johndoe"
    mypwd="john@123"
    myEncodedPwd=ToBase64(myid & ":" & mypwd)
    writeOutput(myEncodedPwd)
</cfscript>

 Adobe

Get help faster and easier

New user?