\Defuse\CryptoEncoding

Summary

Methods
Properties
Constants
binToHex()
hexToBin()
trimTrailingWhitespace()
saveBytesToChecksummedAsciiSafeString()
loadBytesFromChecksummedAsciiSafeString()
No public properties found
CHECKSUM_BYTE_SIZE
CHECKSUM_HASH_ALGO
SERIALIZE_HEADER_BYTES
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

CHECKSUM_BYTE_SIZE

CHECKSUM_BYTE_SIZE

CHECKSUM_HASH_ALGO

CHECKSUM_HASH_ALGO

SERIALIZE_HEADER_BYTES

SERIALIZE_HEADER_BYTES

Methods

binToHex()

binToHex(string  $byte_string) : string

Converts a byte string to a hexadecimal string without leaking information through side channels.

Parameters

string $byte_string

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

Returns

string

hexToBin()

hexToBin(string  $hex_string) : string

Converts a hexadecimal string into a byte string without leaking information through side channels.

Parameters

string $hex_string

Throws

\Defuse\Crypto\Exception\BadFormatException
\Defuse\Crypto\Exception\EnvironmentIsBrokenException

Returns

string

trimTrailingWhitespace()

trimTrailingWhitespace(string  $string = '') : string

Remove trialing whitespace without table look-ups or branches.

Calling this function may leak the length of the string as well as the number of trailing whitespace characters through side-channels.

Parameters

string $string

Returns

string

saveBytesToChecksummedAsciiSafeString()

saveBytesToChecksummedAsciiSafeString(string  $header, string  $bytes) : string

INTERNAL USE ONLY: Applies a version header, applies a checksum, and then encodes a byte string into a range of printable ASCII characters.

Parameters

string $header
string $bytes

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

Returns

string

loadBytesFromChecksummedAsciiSafeString()

loadBytesFromChecksummedAsciiSafeString(string  $expected_header, string  $string) : string

INTERNAL USE ONLY: Decodes, verifies the header and checksum, and returns the encoded byte string.

Parameters

string $expected_header
string $string

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException
\Defuse\Crypto\Exception\BadFormatException

Returns

string