julierme.victor
22nd February 2013, 15:14
Good Morning to All,

I'm needing base64 encode a text, but to use the function base64.decode, I'm not succeeding to convert and thus create a. Xml.

domain tcmcs.str60 filebuffer
domain tcmcs.str60 base64encodebuffer
long filepointer

filebuffer = "TEST"

base64.encode (filebuffer, base64encodebuffer)

Does anyone have a clue to help me?

bdittmar
22nd February 2013, 16:20
Hello,
from LN progguide :

base64.encode()
Syntax:

function long base64.encode (string data.in, ref string data.out)

Description


Encodes the binary input to Base64 encoded output.


Arguments

string data.in String with binary input.

ref string data.out String which will receive the Base64 encoded output. The output is NOT null-terminated.


Return values

The size of the Base64 encoded output is returned. If this value is greater than the size of data.out, then no output at all is written to data.out.

To compute the size of the Base64 encoded output, only the size of the binary input must be known, the actual input itself is not needed. For each three binary input bytes, four Base64 encoded output characters are produced. For any (one or two) remaining binary input bytes at the end, also four Base64 encoded output characters are produced.

So, to compute the size of the Base64 encoded output, divide the size of the binary input by 3, and if that is not an integer, round up to the next integer. Multiply the result by 4.

Context

This function can be used in all script types.

Note
If the input string is not completely filled (only 52 of 60 bytes filled), pass the input string as: your.string(1;number.of.filled.characters). This avoids that the not filled NULL characters are encoded.

bytesread =seq.read( filebuffer, 60, filepointer)
while bytesread > 0
| The last bytestring is usually not completely filled,
| avoid NULL characters in the encoding by passing the number
| of read bytes
base64.encode( filebuffer(1;bytesread), base64encodebuffer )
| do something useful with the base64encodebuffer here
bytesread =seq.read( filebuffer, 60, filepointer)
endwhile

Regards

julierme.victor
22nd February 2013, 16:28
Hello Bernd,

I ran the example that I have attached as progguide.
Eria you a practical example for me to pass?

Regards

vahdani
23rd February 2013, 13:38
Hi,

I think your problem is that you had set the size of the input and base64 buffer to the same value of 64. According to help the output base64 string should be 4/3 times the input buffer. Following code works ok.


function main()
{
string input.buffer(80)
string base64encodebuffer(108) |Size = 4 * buffer/ 3 !!!
long ret
long length

input.buffer = "TEST"
length = len(strip$(input.buffer))

|Test1 with input.buffer limited to filled length (preferred!)
ret = Base64.Encode (input.buffer(1; length), base64encodebuffer)

ret = ret

|ret = 8 |size of base64codedValue
|base64encodebuffer = "VEVTVA=="

|Test2 with total input.buffer
ret = Base64.Encode (input.buffer, base64encodebuffer)

ret = ret

|ret = 108 |size of base64codedValue
|base64encodebuffer = "VEVTVAAAAAAAA...........AAA=="

}

julierme.victor
25th February 2013, 15:00
Hello,

Thank went right solution!

Regards,