Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Base64 Encoding/Decoding

Featured Replies

Hello,

Included with your ScriptMaster plugin is an examples database that contains functions for Base64 encoding/decoding. However, the encoding function inserts returns every 76 characters (as per the Base64 standard). Ideally, I need an encoding function that does *not* insert returns, and I found one in this library:

Apache Commons Codec

My questions revolve around implementing the above library (the library loads just fine). I'm not a Java programmer, but after browsing the library documentation, I came up with the following custom functions:

1) Base64.encode ( text ; chunk )

/**

 Converts any string into another string composed of only the Base64 character set.

  

 @param text *str: any string

 @param chunk *num: 0 (do *not* split into blocks of 76 characters) or 1 (split into blocks of 76 characters)

 @return *str: a string composed of the Base64 characters



*/



Let (

        [

                _result = SMSetVariable( "textToEncode" ; text ) ; 

                _code = "import org.apache.commons.codec.binary.*;" ; 

                _code = _code & Case ( 

                                        chunk ; 

                                        "new String(new Base64().encodeBase64(textToEncode.getBytes(), true));" ; 

                                        "new String(new Base64().encodeBase64(textToEncode.getBytes(), false));"

                                ) 

        ] ;

        

        Case ( not IsEmpty ( text ) ; EvaluateGroovy ( _code ) ) 

)


2) Base64.Decode ( text )




/**

 Converts a string encoded with the Base64 algorithm back to its "natural" form

  

 @param text *str: any string encoded with the Base64 algorithm

 @return *str: a string in its "natural" form



*/



Let (

        [

                _result = SMSetVariable( "encodedText" ; text ) ; 

                _code = "import org.apache.commons.codec.binary.*;" ; 

                _code = _code & "new String(new Base64().decodeBase64(encodedText.getBytes()));" 

        ] ;

        

        Case ( not IsEmpty ( text ) ; EvaluateGroovy ( _code ) ) 

)

The functions seem to work, but I do have some questions:

1) If I want to encode text in the usual way--using Base64.Encode ( text ; 1 )--the encoded text has *two* returns after every 76th character, which seems unexpected. Any ideas why?

2) When sending a return-delimited list from FileMaker to Groovy using the SMSetVariable function, does each return translate to r, n, or rn?

3) When converting an array in Groovy to a return-delimited list using the Array.Join function, for use with the SMGetVariable function, should the join character be r, n, or rn?

Regards,

Sean

  • Author

FYI, the Base64 encoding function supplied with your examples database also adds two returns after every 76th character, but only on Windows.

Hi Grant,

Thanks for the post! I'm looking into the duplicate newline issue.

This issue with newlines was caused by the Base64Encoder class, which uses platform-specific newlines.

Previously, ScriptMaster converted all newline characters to carriage returns, which is how FileMaker wants to receive it. However, when the Base64Encoder is running on windows, it inserts rn for newlines. Then ScriptMaster was converting the second n to a r, leaving two rr in a row.

Version 1.651 (Fresh hot now!) will fix this issue by first checking for carriage returns ® in the returned text on Windows.

-Sam Barnum

360Works

  • Author

Hi Sam,

Thanks for all of your help. FYI, when using the base64 encoding function from the Apache library mentioned in the original post, I still see two returns on the Mac.

  • 4 weeks later...
  • Author

Any luck figuring out why there are two returns inserted after using the Base64 encoding function on a Mac?

  • 4 weeks later...
  • Author

Bumping one final time.

Hi Grant, what version of ScriptMaster are you using?

I believe this has been fixed, the current version is 1.653

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.