Create a public blob from a network `.Message`.

        Specifically, a cert-bearing pubkey auth packet, because by definition
        OpenSSH-style certificates 'are' their own network representation."
359056
def from_message(cls, message):
        
        type_ = message.get_text()
        return cls(type_=type_, blob=message.asbytes())
47299
def create_auth_ack_message(ephemeral_pubkey=nil, nonce=nil, version=SUPPORTED_RLPX_VERSION, eip8=false)
      raise RLPxSessionError, 'must not be initiator' if initiator?

      ephemeral_pubkey = ephemeral_pubkey || @ephemeral_ecc.raw_pubkey
      @responder_nonce = nonce || Crypto.keccak256(Utils.int_to_big_endian(SecureRandom.random_number(TT256)))

      if eip8 || @got_eip8_auth
        msg = create_eip8_auth_ack_message ephemeral_pubkey, @responder_nonce, version
        raise RLPxSessionError, 'invalid msg size' unless msg.size > 97
      else
        msg = "#{ephemeral_pubkey}#{@responder_nonce}\x00"
        raise RLPxSessionError, 'invalid msg size' unless msg.size == 97
      end

      msg
    end
949086
def sign(self, blob, identity):
        """"""
        conn = self.conn_factory()
        return conn.sign_ssh_challenge(blob=blob, identity=identity)
518032
def blob_to_pyasn1(blob):
    

    return pyasn1.codec.der.decoder.decode(
        blob,
        asn1Spec=pyasn1_modules.rfc2459.Certificate()
    )[0]
1141174
def sign(self, message):
		
		return hmac.HMAC(self.key, message, digestmod=hashlib.md5).digest()
441725
def address_from_public_key(pk_bytes):
    
    final_bytes = bytearray()

    # version
    final_bytes.append(6 << 3)
    # public key
    final_bytes.extend(pk_bytes)
    # checksum
    final_bytes.extend(struct.pack("<H", _crc16_checksum(final_bytes)))

    return base64.b32encode(final_bytes).decode()
770471
def load_private_key(pem_path, passphrase_bytes=None):
    """"""
    with open(pem_path, "rb") as f:
        return cryptography.hazmat.primitives.serialization.load_pem_private_key(
            data=f.read(),
            password=passphrase_bytes,
            backend=cryptography.hazmat.backends.default_backend(),
        )
1320618
def privatekey_to_publickey(private_key_bin: bytes) -> bytes:
    
    if not ishash(private_key_bin):
        raise ValueError('private_key_bin format mismatch. maybe hex encoded?')
    return keys.PrivateKey(private_key_bin).public_key.to_bytes()
674296
def encrypt(self, message):
        

        if not isinstance(message, (bytes, str)):
            raise TypeError
        
        return hashlib.sha1(message.encode('utf-8')).hexdigest()
609895
function attach_public_key(&$message)
    {
        $headers = $message->headers();
        $from    = rcube_mime::decode_address_list($headers['From'], 1, false, null, true);
        $from    = $from[1];

        // find my key
        if ($from && ($key = $this->find_key($from, true))) {
            $pubkey_armor = $this->export_key($key->id);

            if (!$pubkey_armor instanceof enigma_error) {
                $pubkey_name = '0x' . enigma_key::format_id($key->id) . '.asc';
                $message->addAttachment($pubkey_armor, 'application/pgp-keys', $pubkey_name, false, '7bit');
                return true;
            }
        }

        return false;
    }
687467
def serialize_cert_to_pem(cert_obj):
    
    return cert_obj.public_bytes(
        encoding=cryptography.hazmat.primitives.serialization.Encoding.PEM
    )
1359130
def sign_ssh_challenge(self, blob, identity):
        """"""
        msg = _parse_ssh_blob(blob)
        log.debug('%s: user %r via %r (%r)',
                  msg['conn'], msg['user'], msg['auth'], msg['key_type'])
        log.debug('nonce: %r', msg['nonce'])
        fp = msg['public_key']['fingerprint']
        log.debug('fingerprint: %s', fp)
        log.debug('hidden challenge size: %d bytes', len(blob))

        log.info('please confirm user "%s" login to "%s" using %s...',
                 msg['user'].decode('ascii'), identity.to_string(),
                 self.device)

        with self.device:
            return self.device.sign(blob=blob, identity=identity)
619420
def create_from_request_pdu(pdu):
        
        _, address, value = struct.unpack('>BHH', pdu)

        value = 1 if value == 0xFF00 else value

        instance = WriteSingleCoil()
        instance.address = address
        instance.value = value

        return instance
658263
def make_signature(signer_func, data_to_sign, public_algo,
                   hashed_subpackets, unhashed_subpackets, sig_type=0):
    """"""
    # pylint: disable=too-many-arguments
    header = struct.pack('>BBBB',
                         4,         # version
                         sig_type,  # rfc4880 (section-5.2.1)
                         public_algo,
                         8)         # hash_alg (SHA256)
    hashed = subpackets(*hashed_subpackets)
    unhashed = subpackets(*unhashed_subpackets)
    tail = b'\x04\xff' + struct.pack('>L', len(header) + len(hashed))
    data_to_hash = data_to_sign + header + hashed + tail

    log.debug('hashing %d bytes', len(data_to_hash))
    digest = hashlib.sha256(data_to_hash).digest()
    log.debug('signing digest: %s', util.hexlify(digest))
    params = signer_func(digest=digest)
    sig = b''.join(mpi(p) for p in params)

    return bytes(header + hashed + unhashed +
                 digest[:2] +  # used for decoder's sanity check
                 sig)
857567
def sign(self, identity, blob):
        """"""
        path = _expand_path(identity.get_bip32_address(ecdh=False))
        if identity.identity_dict['proto'] == 'ssh':
            ins = '04'
            p1 = '00'
        else:
            ins = '08'
            p1 = '00'
        if identity.curve_name == 'nist256p1':
            p2 = '81' if identity.identity_dict['proto'] == 'ssh' else '01'
        else:
            p2 = '82' if identity.identity_dict['proto'] == 'ssh' else '02'
        apdu = '80' + ins + p1 + p2
        apdu = binascii.unhexlify(apdu)
        apdu += bytearray([len(blob) + len(path) + 1])
        apdu += bytearray([len(path) // 4]) + path
        apdu += blob
        log.debug('apdu: %r', apdu)
        result = bytearray(self.conn.exchange(bytes(apdu)))
        log.debug('result: %r', result)
        if identity.curve_name == 'nist256p1':
            offset = 3
            length = result[offset]
            r = result[offset+1:offset+1+length]
            if r[0] == 0:
                r = r[1:]
            offset = offset + 1 + length + 1
            length = result[offset]
            s = result[offset+1:offset+1+length]
            if s[0] == 0:
                s = s[1:]
            offset = offset + 1 + length
            return bytes(r) + bytes(s)
        else:
            return bytes(result[:64])
826861
def from_bytes(cls, bitstream):
        '''
        
        '''
        packet = cls()

        # Convert to ConstBitStream (if not already provided)
        if not isinstance(bitstream, ConstBitStream):
            if isinstance(bitstream, Bits):
                bitstream = ConstBitStream(auto=bitstream)
            else:
                bitstream = ConstBitStream(bytes=bitstream)

        # Read the type
        type_nr = bitstream.read('uint:4')
        if type_nr != packet.message_type:
            msg = 'Invalid bitstream for a {0} packet'
            class_name = packet.__class__.__name__
            raise ValueError(msg.format(class_name))

        # Read if this is a reply
        packet.is_reply = bitstream.read('bool')

        # Skip reserved bits
        packet._reserved1 = bitstream.read(27)

        # Read the nonce
        packet.nonce = bitstream.read('bytes:8')

        # Read the key id
        packet.key_id = bitstream.read('uint:16')

        # Read the authentication data
        data_length = bitstream.read('uint:16')
        packet.authentication_data = bitstream.read('bytes:%d' % data_length)

        # Read the TTL
        packet.ttl = bitstream.read('uint:32')

        # Skip reserved bits
        packet._reserved2 = bitstream.read(8)

        # Store the EID prefix mask length until we need it
        eid_prefix_len = bitstream.read('uint:8')

        # Read the EID prefix
        packet.eid_prefix = read_afi_address_from_bitstream(bitstream, eid_prefix_len)

        # Read the reply
        packet.reply = read_afi_address_from_bitstream(bitstream)

        # Verify that the properties make sense
        packet.sanitize()

        return packet
1321653
def encrypt(receiver_pubhex: str, msg: bytes) -> bytes:
    
    disposable_key = generate_key()
    receiver_pubkey = hex2pub(receiver_pubhex)
    aes_key = derive(disposable_key, receiver_pubkey)
    cipher_text = aes_encrypt(aes_key, msg)
    return disposable_key.public_key.format(False) + cipher_text