[Edit: Replaced function source code with improved version that uses fewer variables and memory.]
Here's a script for a PowerBuilder function I created that performs Base64 encoding that should be compatible with PB 10:
// Public Function: of_Base64Encode(String as_Input) returns String
Constant String BASE64_ENCODING_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Blob lblob_input
Byte lbyte_char
Integer li_rc, li_six_bit_value[4]
Long ll_accumulator, ll_index, ll_blob_length
String ls_encoded_token, ls_output
// Check for null or empty argument string.
If IsNull(as_input) Then
SetNull(ls_output)
Return ls_output
End If
If Len(as_input) = 0 Then Return ""
// Place the input string into a Blob as a series of UTF-8 characters.
// The base64 encoding process encodes thres bytes (characters) of the blob at a time,
// because three bytes = 24 bits, which is evenly divisible by six (bits), producing
// an encoded token of four characters.
lblob_input = Blob(as_input,EncodingUTF8!)
ll_blob_length = Len(lblob_input)
// Encode the blob, up to three bytes (24 bits) at a time.
ls_output = ""
For ll_index = 1 To ll_blob_length Step 3
// Accumulate the next three UTF-8 characters (24 bits) into a Long,
// then separate the bit pattern into four six-bit values.
li_rc = GetByte(lblob_input,ll_index,lbyte_char)
ll_accumulator = lbyte_char * 256
If ll_index+1 <= ll_blob_length Then
li_rc = GetByte(lblob_input,ll_index+1,lbyte_char)
ll_accumulator += lbyte_char
End If
ll_accumulator *= 256
If ll_index+2 <= ll_blob_length Then
li_rc = GetByte(lblob_input,ll_index+2,lbyte_char)
ll_accumulator += lbyte_char
End If
// The low-order 24 bits of the Long now contain the next three UTF-8 characters.
// Split these 24 bits into four six-bit values.
li_six_bit_value[4] = Mod(ll_accumulator,64)
ll_accumulator /= 64
li_six_bit_value[3] = Mod(ll_accumulator,64)
ll_accumulator /= 64
li_six_bit_value[2] = Mod(ll_accumulator,64)
li_six_bit_value[1] = ll_accumulator / 64
// Map the four six-bit values into the base64 encoding map.
// If needed, "padding" values are translated into equal signs (=).
ls_encoded_token = Mid(BASE64_ENCODING_MAP,li_six_bit_value[1]+1,1) + &
Mid(BASE64_ENCODING_MAP,li_six_bit_value[2]+1,1)
If ll_index+1 <= ll_blob_length Then
// Two chars (16 bits) are represented by three six-bit values.
ls_encoded_token += Mid(BASE64_ENCODING_MAP,li_six_bit_value[3]+1,1)
Else
// There was only one character, so append a "pad" encoding character.
ls_encoded_token += "="
End If
If ll_index+2 <= ll_blob_length Then
// Three chars (all 24 bits) are represented by all four six-bit values.
ls_encoded_token += Mid(BASE64_ENCODING_MAP,li_six_bit_value[4]+1,1)
Else
// There were only one or two characters, so append a "pad" encoding character.
ls_encoded_token += "="
End If
// Append the Base64-encoded token onto the output string, and repeat.
ls_output += ls_encoded_token
Next
// Done!
Return ls_output
HTH, John