base64.c
April 3, 2026 ยท View on GitHub
Purpose
Standard and URL-safe Base64 encode/decode helpers.
API Reference
char *XBase64_Encrypt(const uint8_t *pInput, size_t *pLength)
- Arguments:
pInput: source bytes.pLength: in/out length pointer; input size on entry, encoded length on success.
- Does:
- encodes input with standard Base64 alphabet and
=padding.
- encodes input with standard Base64 alphabet and
- Returns:
- newly allocated NUL-terminated string on success.
NULLwhenpInput == NULL,pLength == NULL,*pLength == 0or allocation fails.
char *XBase64_Decrypt(const uint8_t *pInput, size_t *pLength)
- Arguments:
pInput: Base64 text.pLength: in/out length pointer; encoded size on entry, decoded byte count on success.
- Does:
- accepts both properly padded input and missing-padding input.
- internally rounds the length to a multiple of 4 when necessary.
- Returns:
- newly allocated decoded buffer on success.
NULLon invalid args or allocation failure.
char *XBase64_UrlEncrypt(const uint8_t *pInput, size_t *pLength)
- Arguments:
- same shape as
XBase64_Encrypt.
- same shape as
- Does:
- uses URL-safe alphabet
-and_. - strips trailing
=padding from the textual result.
- uses URL-safe alphabet
- Returns:
- newly allocated encoded string or
NULL.
- newly allocated encoded string or
char *XBase64_UrlDecrypt(const uint8_t *pInput, size_t *pLength)
- Arguments:
- same shape as
XBase64_Decrypt.
- same shape as
- Does:
- converts URL-safe alphabet back to standard Base64.
- then decodes through the standard decoder.
- Returns:
- newly allocated decoded buffer or
NULL.
- newly allocated decoded buffer or
Notes
- Decoded buffers are convenient for text because the implementation appends a trailing NUL, but the authoritative size is always
*pLength.