Esempio n. 1
0
    def ToHexString(data_bytes: bytes, encoding: str = "utf-8") -> str:
        """
        Convert bytes to hex string.

        Args:
            data_bytes (bytes)      : Data bytes
            encoding (str, optional): Encoding type, utf-8 by default

        Returns:
            str: Bytes converted to hex string
        """
        return AlgoUtils.Decode(binascii.hexlify(data_bytes), encoding)
Esempio n. 2
0
    def Encode(data: Union[bytes, str],
               custom_alphabet: Optional[str] = None) -> str:
        """
        Encode to Base32.

        Args:
            data (str or bytes)            : Data
            custom_alphabet (str, optional): Custom alphabet string

        Returns:
            str: Encoded string
        """
        b32_enc = AlgoUtils.Decode(base64.b32encode(AlgoUtils.Encode(data)))
        if custom_alphabet is not None:
            b32_enc = _Base32Utils.TranslateAlphabet(b32_enc,
                                                     Base32Const.ALPHABET,
                                                     custom_alphabet)

        return b32_enc