3 library(crypto): Cryptography and authentication library
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog SSL Interface
        • library(crypto): Cryptography and authentication library
          • Introduction
          • Design principle: Secure default algorithms
          • Representing binary data
            • hex_bytes/2
          • Cryptographically secure random numbers
          • Hashes
          • Digital signatures
          • Asymmetric encryption and decryption
          • Symmetric encryption and decryption
          • Number theory
          • Elliptic curves
          • Example: Establishing a shared secret

3.3 Representing binary data

In the context of this library, bytes can be represented as lists of integers between 0 and 255. Such lists can be converted to and from hexadecimal notation with the following bidirectional relation:

[det]hex_bytes(?Hex, ?List)
Relation between a hexadecimal sequence and a list of bytes. Hex is an atom, string, list of characters or list of codes in hexadecimal encoding. This is the format that is used by crypto_data_hash/3 and related predicates to represent hashes. Bytes is a list of integers between 0 and 255 that represent the sequence as a list of bytes. At least one of the arguments must be instantiated. When converting List to Hex, an atom is used to represent the sequence of hexadecimal digits.

Example:

?- hex_bytes('501ACE', Bs).
Bs = [80, 26, 206].
See also
base64_encoded/3 for Base64 encoding, which is often used to transfer or embed binary data in applications.