How to use the libnacl.encode.hex_decode function in libnacl

To help you get started, we’ve selected a few libnacl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lgrahl / threema-msgapi-sdk-python / threema / gateway / key.py View on Github external
"""
        # Split key
        try:
            type_, key = encoded_key.split(Key.separator)
        except ValueError as exc:
            raise GatewayKeyError('Invalid key format') from exc
        type_ = Key.Type(type_)

        # Check type
        if type_ != expected_type:
            raise GatewayKeyError('Invalid key type: {}, expected: {}'.format(
                type_, expected_type
            ))

        # De-hexlify
        key = libnacl.encode.hex_decode(key)

        # Convert to SecretKey or PublicKey
        if type_ == Key.Type.private:
            key = libnacl.public.SecretKey(key)
        elif type_ == Key.Type.public:
            key = libnacl.public.PublicKey(key)

        return key
github JoinMarket-Org / joinmarket / lib / libnacl / sign.py View on Github external
def __init__(self, vk_hex):
        '''
        Create a verification key from a hex encoded vkey
        '''
        self.vk = libnacl.encode.hex_decode(vk_hex)
github lgrahl / threema-msgapi-sdk-python / threema / gateway / _gateway.py View on Github external
def get_public_key(self, id_):
        """
        Get the public key of a Threema ID.

        Arguments:
            - `id_`: A Threema ID.

        Return a :class:`libnacl.public.PublicKey` for a Threema ID.
        """
        response = yield from self._get(self.urls['get_public_key'].format(id_))
        if response.status == 200:
            text = yield from response.text()
            key = libnacl.encode.hex_decode(text)
            return libnacl.public.PublicKey(key)
        else:
            yield from raise_server_error(response, KeyServerError)
github saltstack / libnacl / libnacl / utils.py View on Github external
libnacl.encode.hex_decode(key_data['priv']),
                libnacl.encode.hex_decode(key_data['sign']))
    elif 'priv' in key_data and 'pub' in key_data:
        return libnacl.public.SecretKey(
                libnacl.encode.hex_decode(key_data['priv']))
    elif 'sign' in key_data:
        return libnacl.sign.Signer(
                libnacl.encode.hex_decode(key_data['sign']))
    elif 'pub' in key_data:
        return libnacl.public.PublicKey(
                libnacl.encode.hex_decode(key_data['pub']))
    elif 'verify' in key_data:
        return libnacl.sign.Verifier(key_data['verify'])
    elif 'priv' in key_data:
        return libnacl.secret.SecretBox(
                libnacl.encode.hex_decode(key_data['priv']))
    raise ValueError('Found no key data')
github saltstack / libnacl / libnacl / utils.py View on Github external
import msgpack
            key_data = msgpack.load(stream)
        elif serial == 'json':
            import json
            if sys.version_info[0] >= 3:
                key_data = json.loads(stream.read())
            else:
                key_data = json.loads(stream.read(), encoding='UTF-8')
    finally:
        if stream != path_or_file:
            stream.close()

    if 'priv' in key_data and 'sign' in key_data and 'pub' in key_data:
        return libnacl.dual.DualSecret(
                libnacl.encode.hex_decode(key_data['priv']),
                libnacl.encode.hex_decode(key_data['sign']))
    elif 'priv' in key_data and 'pub' in key_data:
        return libnacl.public.SecretKey(
                libnacl.encode.hex_decode(key_data['priv']))
    elif 'sign' in key_data:
        return libnacl.sign.Signer(
                libnacl.encode.hex_decode(key_data['sign']))
    elif 'pub' in key_data:
        return libnacl.public.PublicKey(
                libnacl.encode.hex_decode(key_data['pub']))
    elif 'verify' in key_data:
        return libnacl.sign.Verifier(key_data['verify'])
    elif 'priv' in key_data:
        return libnacl.secret.SecretBox(
                libnacl.encode.hex_decode(key_data['priv']))
    raise ValueError('Found no key data')
github saltstack / libnacl / libnacl / utils.py View on Github external
import json
            if sys.version_info[0] >= 3:
                key_data = json.loads(stream.read())
            else:
                key_data = json.loads(stream.read(), encoding='UTF-8')
    finally:
        if stream != path_or_file:
            stream.close()

    if 'priv' in key_data and 'sign' in key_data and 'pub' in key_data:
        return libnacl.dual.DualSecret(
                libnacl.encode.hex_decode(key_data['priv']),
                libnacl.encode.hex_decode(key_data['sign']))
    elif 'priv' in key_data and 'pub' in key_data:
        return libnacl.public.SecretKey(
                libnacl.encode.hex_decode(key_data['priv']))
    elif 'sign' in key_data:
        return libnacl.sign.Signer(
                libnacl.encode.hex_decode(key_data['sign']))
    elif 'pub' in key_data:
        return libnacl.public.PublicKey(
                libnacl.encode.hex_decode(key_data['pub']))
    elif 'verify' in key_data:
        return libnacl.sign.Verifier(key_data['verify'])
    elif 'priv' in key_data:
        return libnacl.secret.SecretBox(
                libnacl.encode.hex_decode(key_data['priv']))
    raise ValueError('Found no key data')
github duniter / duniter-python-api / duniterpy / tools.py View on Github external
def convert_seedhex_to_seed(seedhex: str) -> bytes:
    """
    Convert seedhex to seed

    :param seedhex: seed coded in hexadecimal base
    :rtype bytes:
    """
    return bytes(hex_decode(seedhex.encode("utf-8")))
github saltstack / libnacl / libnacl / utils.py View on Github external
if stream != path_or_file:
            stream.close()

    if 'priv' in key_data and 'sign' in key_data and 'pub' in key_data:
        return libnacl.dual.DualSecret(
                libnacl.encode.hex_decode(key_data['priv']),
                libnacl.encode.hex_decode(key_data['sign']))
    elif 'priv' in key_data and 'pub' in key_data:
        return libnacl.public.SecretKey(
                libnacl.encode.hex_decode(key_data['priv']))
    elif 'sign' in key_data:
        return libnacl.sign.Signer(
                libnacl.encode.hex_decode(key_data['sign']))
    elif 'pub' in key_data:
        return libnacl.public.PublicKey(
                libnacl.encode.hex_decode(key_data['pub']))
    elif 'verify' in key_data:
        return libnacl.sign.Verifier(key_data['verify'])
    elif 'priv' in key_data:
        return libnacl.secret.SecretBox(
                libnacl.encode.hex_decode(key_data['priv']))
    raise ValueError('Found no key data')