Create a base64 coded string of a given char* string.

Create a base64 coded string of a given char* string. The result must deleted using release.

Name Type Default Description
Return char*   New created char* string with the base64 coded input string. Must released using release!
txt char* - any char* string
bufferLength int -1 Length of the input buffer. When this parameter is smaller or equal to 0, the length of the input buffer is determined automatically (only works for zero-terminated char* buffers!). When you want to encode binary data, provide the length of the input buffer here.

Encoding the current text and decoding this result must be equal.

int main ()
{
    String			str	= string::alloc ();
    char		*	enc	= 0;
    char		*	dec	= 0;
textmodel::gettext (str);
enc = encode_base64 (string::get (str)); dec = decode_base64 (enc);
showmessage ("%s\n\n%s\n\n%d", enc, dec, strcmp (string::get (str), dec));
release (enc); release (dec);
return 0; }

Write the content of the current textmodel base64 encoded to a file. After reading and decoding this files boths strings must be equal. Take care to use a big enoug buffer while reading or read and decoded using a loop.

int main ()
{
    String			str	= string::alloc ();
    char		*	enc	= 0;
    char		*	dec	= 0;
    char			buf	[3001];
    int				fi	= 0;
textmodel::gettext (str);
// Encode to file enc = encode_base64 (string::get (str));
fi = file::open ("$DESKTOP/txt.txt", "w"); file::write (fi, enc); file::close (fi);
// Decode from file fi = file::open ("$DESKTOP/txt.txt", "r"); file::read (fi, buf, 3000); file::close (fi); dec = decode_base64 (buf);
showmessage ("%s\n\n%s\n\n%d", enc, dec, strcmp (string::get (str), dec));
release (enc); release (dec);
return 0; }

Since
Version 3.2.2 R2366, 2803.2011

Available
priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

See Also
decode_base64

Alphabetic index HTML hierarchy of classes or Java