---
name: "libwget-base64"
section: "3"
platform: "linux"
package: "wget2-dev"
version: "2.2.0+ds-1+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/libwget-base64"
---

# libwget-base64(3)

Base64 functions

## NAME

libwget-base64 - Base64 functions

## SYNOPSIS

### Macros

\#define **WGET\_BASE64\_URLENCODE**   1\

### Functions

bool **wget\_base64\_is\_string** (const char \*src)\
 size\_t **wget\_base64\_decode** (char \*dst, const char \*src, size\_t n)\
 char \* **wget\_base64\_decode\_alloc** (const char \*src, size\_t n, size\_t \*outlen)\
 size\_t **wget\_base64\_encode** (char \*dst, const char \*src, size\_t n)\
 size\_t **wget\_base64\_urlencode** (char \*dst, const char \*src, size\_t n)\
 char \* **wget\_base64\_encode\_alloc** (const char \*src, size\_t n)\
 char \* **wget\_base64\_encode\_vprintf\_alloc** (const char \*fmt, va\_list args)\
 char \* **wget\_base64\_encode\_printf\_alloc** (const char \*fmt,...)\
 size\_t **wget\_base64\_get\_decoded\_length** (size\_t len)\
 size\_t **wget\_base64\_get\_encoded\_length** (size\_t len)\

## Detailed Description

This is a collection base64 encoding/decoding functions used in Wget2.

## Function Documentation

### bool wget\_base64\_is\_string (const char \* src)

**Parameters**

*src* String to be checked

**Returns**

1 if `src` is a base64 string, 0 otherwise

Checks whether `src` is a base64 string. Returns 0 if `src` is NULL.

### size\_t wget\_base64\_decode (char \* dst, const char \* src, size\_t n)

**Parameters**

*dst* Output buffer \
 *src* Base64 string to be decoded \
 *n* Length of `src`

**Returns**

Number of bytes written into `dst`

Decodes `n` bytes of the base64 string `src`. The decoded bytes are written into `dst` and are 0-terminated.

The size of `dst` has to be at minimum ((`n` + 3) / 4) \* 3 + 1 bytes.

### char \* wget\_base64\_decode\_alloc (const char \* src, size\_t n, size\_t \* outlen)

**Parameters**

*src* Base64 string to be decoded \
 *n* Length of `src` \
 *outlen* Length of returned string, may be NULL.

**Returns**

Decoded bytes, zero terminated. Returns NULL if memory allocation failed.

Decodes `n` bytes of the base64 string `src`. The decoded bytes are returned in an allocated buffer.

You should free() the returned string when not needed any more.

### size\_t wget\_base64\_encode (char \* dst, const char \* src, size\_t n)

**Parameters**

*dst* Base64 output string \
 *src* Input buffer \
 *n* Number of bytes to be encoded

**Returns**

Length of output string `dst`

Encodes `n` bytes from `src` into a base64 string. The encoded string is written into `dst` (0-terminated).

The length of `dst` has to be at minimum ((`n` + 2) / 3) \* 4 + 1 bytes.

### size\_t wget\_base64\_urlencode (char \* dst, const char \* src, size\_t n)

**Parameters**

*dst* Base64 output string (URL and filename safe) \
 *src* Input buffer \
 *n* Number of bytes to be encoded

**Returns**

Length of output string `dst`

Encodes `n` bytes from `src` into a base64 URL and filename safe string (see RFC 4648, 5.). The encoded string is written into `dst` (0-terminated).

The length of `dst` has to be at minimum ((`n` + 2) / 3) \* 4 + 1 bytes.

### char \* wget\_base64\_encode\_alloc (const char \* src, size\_t n)

**Parameters**

*src* Input buffer \
 *n* Number of bytes to be encoded

**Returns**

Base64 encoded string or NULL if memory allocation failed

Encodes `n` bytes from input buffer `src`. The encoded string is returned in an allocated buffer.

You should free() the returned string when not needed any more.

### char \* wget\_base64\_encode\_vprintf\_alloc (const char \* fmt, va\_list args)

**Parameters**

*fmt* Printf-like format string \
 *args* Argument list

**Returns**

Base64 encoded string

Encodes the string constructed by `fmt` and `args`. The encoded string is returned in an allocated buffer.

You should free() the returned string when not needed any more.

### char \* wget\_base64\_encode\_printf\_alloc (const char \* fmt, ...)

**Parameters**

*fmt* Printf-like format string \
 *...* Argument list

**Returns**

Base64 encoded string

Encodes the string constructed by `fmt` and the arguments. The encoded string is returned in an allocated buffer.

You should free() the returned string when not needed any more.

### static inline size\_t wget\_base64\_get\_decoded\_length (size\_t len)

**Parameters**

*len* Length of base64 sequence

**Returns**

Number of decoded bytes plus one (for 0-byte termination)

Calculate the number of bytes needed for decoding a base64 sequence with length `len`.

### static inline size\_t wget\_base64\_get\_encoded\_length (size\_t len)

**Parameters**

*len* Number of (un-encoded) bytes

**Returns**

Length of base64 encoding plus one (for 0-byte termination)

Calculate the number of bytes needed for base64 encoding a byte sequence with length `len`, including the padding and 0-termination bytes.

## Author

Generated automatically by Doxygen for wget2 from the source code.
