# binascii

Starlark module for working with binascii libarary.

The binascii module contains a number of methods to convert between binary and various ASCII-encoded binary representations. Normally, you will not use these functions directly but use wrapper modules like uu, base64, or binhex instead. The binascii module contains low-level functions written in C for greater speed that are used by the higher-level modules.

Similar to [binascii in Python](https://docs.python.org/3/library/binascii.html).

## binascii.a2b\_base64(data)

Convert a block of base64 data back to binary and return the binary data. More than one line may be passed at a time.

Example:

```python
binascii.a2b_base64('bGFya3k=')
b'larky'
```

**Parameters:**

**data** – base64 encoded string.

*Returns:* decoded binary data.

## binascii.a2b\_hex(hexstr)

Return the binary data represented by the hexadecimal string hexstr. This function is the inverse of b2a\_hex(). hexstr must contain an even number of hexadecimal digits (which can be upper or lower case), otherwise an Error exception is raised.

Similar functionality (accepting only text string arguments, but more liberal towards whitespace) is also accessible using the bytes.fromhex() method.

Same as unhexlify()

```python
binascii.a2b_hex('6c61726b79')
b'larky'
```

**Parameters:**

**hexstr** – hexadecimal encoded string (must contain an even number of hex digits (upper or lower case)).

*Returns:* decoded binary data.

## binascii.b2a\_base64(data)

Convert binary data to a line of ASCII characters in base64 coding. The return value is the converted line, including a newline char if newline is true. The output of this function conforms to RFC 3548.

```python
binascii.b2a_hex('larky')
b'bGFya3k='
```

**Parameters:**

**data** – bytes string.

*Returns:* base64 encoded bytes.

## binascii.b2a\_hex(data)

Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. The returned bytes object is therefore twice as long as the length of data.

Similar functionality (but returning a text string) is also conveniently accessible using the bytes.hex() method.

If sep is specified, it must be a single character str or bytes object. It will be inserted in the output after every bytes\_per\_sep input bytes. Separator placement is counted from the right end of the output by default, if you wish to count from the left, supply a negative bytes\_per\_sep value. Same as hexlify()

Example:

```python
binascii.b2a_hex(b'\xb9\x01\xef')
b'b901ef'
binascii.hexlify(b'\xb9\x01\xef', ':')
b'b9:01:ef'
binascii.b2a_hex(b'\xb9\x01\xef', b'_', 2)
b'b9_01ef'
```

**Parameters:**

**data** – bytes string.

*Returns:* binary data in hexadecimal.

## binascii.crc32(data, value=0)

Compute CRC-32, the 32-bit checksum of data, starting with an initial CRC of value. The default initial CRC is zero. The algorithm is consistent with the ZIP file checksum. Since the algorithm is designed for use as a checksum algorithm, it is not suitable for use as a general hash algorithm.

```python
binascii.crc32(b'larky')
3789503229
crc = binascii.crc32(b'larky')
binascii.crc32(b'larky', crc)
257754740
```

**Parameters:**

* **data** – bytes string.
* **value** – initial CEC.

*Returns:* data crc32 checksum.

## binascii.hexlify(data)

Hexadecimal representation of binary data The return value is a bytes object. Same as b2a\_hex()

**Parameters:**

**data** – bytes string.

*Returns:* binary data in hexadecimal.

## binascii.unhexlify(hexstr)

Binary data of hexadecimal representation Same as a2b\_hex()

**Parameters:**

**hexstr** – hexadecimal encoded string (must contain an even number of hex digits (upper or lower case)).

*Returns:* decoded binary data.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/larky/library-api/binascii.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
