Create an SSH key in MAAS with the content in `key`.

        :param key: The content of the SSH key
        :type key: `str`
        :returns: The created SSH key
        :rtype: `SSHKey`
195429
async def create(cls, key: str):
        
        return cls._object(await cls._handler.create(key=key))
842140
def generate_ssh_key(self):
        
        web_command(
            command=["ssh-keygen", "-q", "-t", "rsa", "-N", "", "-C",
                     "datacats generated {0}@{1}".format(
                         getuser(), gethostname()),
                     "-f", "/output/id_rsa"],
            rw={self.profiledir: '/output'},
            )
765931
def rm_auth_key(user,
                key,
                config='.ssh/authorized_keys',
                fingerprint_hash_type=None):
    '''
    
    '''
    current = auth_keys(user,
                        config=config,
                        fingerprint_hash_type=fingerprint_hash_type)
    linere = re.compile(r'^(.*?)\s?((?:ssh\-|ecds)[\w-]+\s.+)$')
    if key in current:
        # Remove the key
        full = _get_config_file(user, config)

        # Return something sensible if the file doesn't exist
        if not os.path.isfile(full):
            return 'Authorized keys file {0} not present'.format(full)

        lines = []
        try:
            # Read every line in the file to find the right ssh key
            # and then write out the correct one. Open the file once
            with salt.utils.files.fopen(full, 'r') as _fh:
                for line in _fh:
                    # We don't need any whitespace-only containing lines or arbitrary doubled newlines
                    line = salt.utils.stringutils.to_unicode(line.strip())
                    if line == '':
                        continue
                    line += '\n'

                    if line.startswith('#'):
                        # Commented Line
                        lines.append(line)
                        continue

                    # get "{options} key"
                    search = re.search(linere, line)
                    if not search:
                        # not an auth ssh key, perhaps a blank line
                        continue

                    comps = search.group(2).split()

                    if len(comps) < 2:
                        # Not a valid line
                        lines.append(line)
                        continue

                    pkey = comps[1]

                    # This is the key we are "deleting", so don't put
                    # it in the list of keys to be re-added back
                    if pkey == key:
                        continue

                    lines.append(line)

            # Let the context manager do the right thing here and then
            # re-open the file in write mode to save the changes out.
            with salt.utils.files.fopen(full, 'wb') as _fh:
                _fh.writelines(salt.utils.data.encode(lines))
        except (IOError, OSError) as exc:
            log.warning('Could not read/write key file: %s',
                        exc)
            return 'Key not removed'
        return 'Key removed'
    # TODO: Should this function return a simple boolean?
    return 'Key not present'
392909
def _add_ssh_key(ret):
    '''
    
    '''
    priv = None
    if __opts__.get('ssh_use_home_key') and os.path.isfile(os.path.expanduser('~/.ssh/id_rsa')):
        priv = os.path.expanduser('~/.ssh/id_rsa')
    else:
        priv = __opts__.get(
            'ssh_priv',
            os.path.abspath(os.path.join(
                __opts__['pki_dir'],
                'ssh',
                'salt-ssh.rsa'
            ))
        )
    if priv and os.path.isfile(priv):
        ret['priv'] = priv
13312
def _use_ssh_config(self, dict_arg):
        
        connect_dict = dict_arg.copy()

        # Use SSHConfig to generate source content.
        full_path = path.abspath(path.expanduser(self.ssh_config_file))
        if path.exists(full_path):
            ssh_config_instance = paramiko.SSHConfig()
            with io.open(full_path, "rt", encoding="utf-8") as f:
                ssh_config_instance.parse(f)
                source = ssh_config_instance.lookup(self.host)
        else:
            source = {}

        if "proxycommand" in source:
            proxy = paramiko.ProxyCommand(source["proxycommand"])
        elif "ProxyCommand" in source:
            proxy = paramiko.ProxyCommand(source["ProxyCommand"])
        else:
            proxy = None

        # Only update 'hostname', 'sock', 'port', and 'username'
        # For 'port' and 'username' only update if using object defaults
        if connect_dict["port"] == 22:
            connect_dict["port"] = int(source.get("port", self.port))
        if connect_dict["username"] == "":
            connect_dict["username"] = source.get("user", self.username)
        if proxy:
            connect_dict["sock"] = proxy
        connect_dict["hostname"] = source.get("hostname", self.host)

        return connect_dict
1285786
def load_key(self, key):
        

        self._serialize(key)
        if isinstance(key, rsa.RSAPrivateKey):
            self.priv_key = key
            self.pub_key = key.public_key()
        else:
            self.pub_key = key

        return self
1103559
def update_ssh_key(self, name):
        # The `_ssh_key` is to avoid conflicts with MutableMapping.update.
        
        api = self.doapi_manager
        return api._ssh_key(api.request(self.url, method='PUT',
                                       data={"name": name})["ssh_key"])
180287
def get(self, key_id=None):
        
        url = self.bitbucket.url('GET_SSH_KEY', key_id=key_id)
        return self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth)
1075364
def get_hmac(self, key):
        
        h = HMAC.new(key, None, SHA256)
        h.update(self.iv)
        h.update(str(self.chunks).encode())
        h.update(self.f_key)
        h.update(self.alpha_key)
        h.update(str(self.encrypted).encode())
        return h.digest()
377802
def create_key(policy=None, description=None, key_usage=None, region=None,
               key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    r = {}
    _policy = salt.serializers.json.serialize(policy)
    try:
        key_metadata = conn.create_key(
            _policy,
            description=description,
            key_usage=key_usage
        )
        r['key_metadata'] = key_metadata['KeyMetadata']
    except boto.exception.BotoServerError as e:
        r['error'] = __utils__['boto.get_error'](e)
    return r
45322
def _create_handshake(channel, key):
    
    hsk = Handshake()
    hsk.channel = channel
    hsk.streamKey = key
    return hsk
1334675
def set_key(key: str, value: str) -> dict:
    
    if not _conf.path:
        return {}

    if "toml" in _conf.path:
        with open(_conf.path, "r") as f:
            parser = parse(f.read())
        parser["tool"]["commitizen"][key] = value
        with open(_conf.path, "w") as f:
            f.write(parser.as_string())
    else:
        parser = configparser.ConfigParser()
        parser.read(_conf.path)
        parser["commitizen"][key] = value
        with open(_conf.path, "w") as f:
            parser.write(f)

    return _conf.config
161006
def make_signature(params, hmac_key):
    
    # produce a list of "key=value" for all entries in params except `h'
    pairs = [x + "=" + ''.join(params[x]) for x in sorted(params.keys()) if x != "h"]
    sha = hmac.new(hmac_key, '&'.join(pairs), hashlib.sha1)
    return base64.b64encode(sha.digest())
911368
def hmac_sha256(key, msg):
    

    return hmac.new(key, msg, hashlib.sha256).digest()
539940
def initialize_key(self, key):
        
        self.k = key
        self.n = 0
        if self.has_key():
            self.cipher.initialize(key)
563206
def create_key(tc, pykey):
    
    try:
        k_enc = tc.encode_key(pykey)
        if not k_enc:
            if not pykey:
                excls = ArgumentError
            else:
                excls = ValueFormatError
            raise excls.pyexc("Key is empty", obj=pykey)

    except (ValueFormatError, ArgumentError):
        raise
    except Exception as e:
        raise ValueFormatError.pyexc(inner=e)

    s_key = ffi.new('char[]', k_enc)
    return s_key, len(k_enc)
1026649
def generate_ssh_key():
    

    key = rsa.generate_private_key(
        backend=default_backend(),
        public_exponent=65537,
        key_size=4096
        )
    private_key = key.private_bytes(
        serialization.Encoding.PEM,
        serialization.PrivateFormat.PKCS8,
        serialization.NoEncryption())
    public_key = key.public_key().public_bytes(
        serialization.Encoding.OpenSSH,
        serialization.PublicFormat.OpenSSH
    )

    return private_key, public_key