# Base64 Encode/Decode

**API Group:** `xmlsec_core_base64`

Base64 encoding/decoding functions and transform implementation.

Base64 encoding/decoding functions.

## Macros

### `XMLSEC_BASE64_LINESIZE`

*Defined as:* `64`

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L26)

The default maximum base64 encoded line size.

---

## Functions

### `xmlSecBase64GetDefaultLineSize`

```c
int xmlSecBase64GetDefaultLineSize(void);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L28)

Gets the current default line size.

**Returns:** The current default line size.

---

### `xmlSecBase64SetDefaultLineSize`

```c
void xmlSecBase64SetDefaultLineSize(int columns);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L29)

Sets the current default line size.

**Parameters:**

- `columns` — number of columns

---

### `xmlSecBase64CtxCreate`

```c
xmlSecBase64CtxPtr xmlSecBase64CtxCreate(int encode, int columns);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L37)

Allocates and initializes new base64 context.

**Parameters:**

- `encode` — the encode/decode flag (1 - encode, 0 - decode).
- `columns` — the max line length.


**Returns:** a pointer to newly created xmlSecBase64Ctx structure or NULL if an error occurs.

---

### `xmlSecBase64CtxDestroy`

```c
void xmlSecBase64CtxDestroy(xmlSecBase64CtxPtr ctx);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L39)

Destroys base64 context.

**Parameters:**

- `ctx` — the pointer to xmlSecBase64Ctx structure.

---

### `xmlSecBase64CtxInitialize`

```c
int xmlSecBase64CtxInitialize(xmlSecBase64CtxPtr ctx, int encode, int columns);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L40)

Initializes new base64 context.

**Parameters:**

- `ctx` — the pointer to xmlSecBase64Ctx structure,
- `encode` — the encode/decode flag (1 - encode, 0 - decode)
- `columns` — the max line length.


**Returns:** 0 on success and a negative value otherwise.

---

### `xmlSecBase64CtxFinalize`

```c
void xmlSecBase64CtxFinalize(xmlSecBase64CtxPtr ctx);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L43)

Frees all the resources allocated by `ctx`.

**Parameters:**

- `ctx` — the pointer to xmlSecBase64Ctx structure,

---

### `xmlSecBase64CtxUpdate_ex`

```c
int xmlSecBase64CtxUpdate_ex(xmlSecBase64CtxPtr ctx, const xmlSecByte *in, xmlSecSize inSize, xmlSecByte *out, xmlSecSize outSize, xmlSecSize *outWritten);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L44)

Encodes or decodes the next piece of data from input buffer.

Encodes or decodes the next piece of data from input buffer. 

**Parameters:**

- `ctx` — the pointer to xmlSecBase64Ctx structure
- `in` — the input buffer
- `inSize` — the input buffer size
- `out` — the output buffer
- `outSize` — the output buffer size
- `outWritten` — the pointer to store the number of bytes written into the output


**Returns:** 0 on success and a negative value otherwise.

---

### `xmlSecBase64CtxFinal_ex`

```c
int xmlSecBase64CtxFinal_ex(xmlSecBase64CtxPtr ctx, xmlSecByte *out, xmlSecSize outSize, xmlSecSize *outWritten);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L50)

Finishes encoding or decoding and returns the result.

Encodes or decodes the last piece of data stored in the context and finalizes the result. 

**Parameters:**

- `ctx` — the pointer to xmlSecBase64Ctx structure
- `out` — the output buffer
- `outSize` — the output buffer size
- `outWritten` — the pointer to store the number of bytes written into the output


**Returns:** 0 on success and a negative value otherwise.

---

### `xmlSecBase64Encode`

```c
xmlChar * xmlSecBase64Encode(const xmlSecByte *in, xmlSecSize inSize, int columns);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L56)

Encodes data to a base64 string.

Encodes the data from input buffer and allocates the string for the result. The caller is responsible for freeing returned buffer using xmlFree() function. 

**Parameters:**

- `in` — the input buffer.
- `inSize` — the input buffer size.
- `columns` — the output max line length (if 0 then no line breaks would be inserted)


**Returns:** newly allocated string with base64 encoded data or NULL if an error occurs.

---

### `xmlSecBase64Decode_ex`

```c
int xmlSecBase64Decode_ex(const xmlChar *str, xmlSecByte *out, xmlSecSize outSize, xmlSecSize *outWritten);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L59)

Decodes a base64 encoded string into the output buffer.

Decodes input base64 encoded string and puts result into the output buffer. 

**Parameters:**

- `str` — the input buffer with base64 encoded string
- `out` — the output buffer
- `outSize` — the output buffer size
- `outWritten` — the pointer to store the number of bytes written into the output.


**Returns:** 0 on success and a negative value otherwise.

---

### `xmlSecBase64DecodeInPlace`

```c
int xmlSecBase64DecodeInPlace(xmlChar *str, xmlSecSize *outWritten);
```

*Source:* [include/xmlsec/base64.h](https://github.com/lsh123/xmlsec/blob/1.3.11/include/xmlsec/base64.h#L63)

Decodes a base64 encoded string in-place.

Decodes input base64 encoded string from `str` "in-place" (i.e. puts results into `str` buffer). 

**Parameters:**

- `str` — the input/output buffer
- `outWritten` — the pointer to store the number of bytes written into the output.


**Returns:** 0 on success and a negative value otherwise.

---
