Base64

Base64 — Base64 encoding and decoding

Synopsis




gchar*      gnet_base64_encode              (gchar *src,
                                             gint srclen,
                                             gint *dstlenp,
                                             gboolean strict);
gchar*      gnet_base64_decode              (gchar *src,
                                             gint srclen,
                                             gint *dstlenp);

Description

gchar* binary_stream = "Hello World!";
gchar* base64_stream;
gint   base64_len;
gchar* newbin_stream;
gint   newbin_len;

base64_stream = gnet_base64_encode(binary_stream,strlen(binary_stream), &base64_len, FALSE);
newbin_stream = gnet_base64_decode(base64_stream, base64_len, &newbin_len);

This module provides functions to encode and decode strings into the Base64 encoding specified in "RFC 2045 - MIME (Multipurpose Internet Mail Extensions)". The Base64 encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable. A 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be represented per printable character.

Details

gnet_base64_encode ()

gchar*      gnet_base64_encode              (gchar *src,
                                             gint srclen,
                                             gint *dstlenp,
                                             gboolean strict);

Convert a buffer from binary to base64 representation. Set strict to TRUE to insert a newline every 72th character. This is required by RFC 2045, but some applications don't require this.

src : source buffer
srclen : length of the source buffer
dstlenp : length of the buffer returned (including the terminating \0)
strict : insert new lines as required by RFC 2045
Returns : caller-owned buffer.

gnet_base64_decode ()

gchar*      gnet_base64_decode              (gchar *src,
                                             gint srclen,
                                             gint *dstlenp);

Convert a buffer from base64 to binary representation. This function is liberal in what it will accept. It ignores non-base64 symbols.

src : the source buffer
srclen : the length of the source buffer
dstlenp : pointer to length of the destination buffer
Returns : caller-owned buffer. The integer pointed to by dstlenp is set to the length of that buffer.