当前位置: 首页>>代码示例>>Python>>正文


Python RSAKey.encode方法代码示例

本文整理汇总了Python中paramiko.rsakey.RSAKey.encode方法的典型用法代码示例。如果您正苦于以下问题:Python RSAKey.encode方法的具体用法?Python RSAKey.encode怎么用?Python RSAKey.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在paramiko.rsakey.RSAKey的用法示例。


在下文中一共展示了RSAKey.encode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: from_line

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import encode [as 别名]
    def from_line(cls, line, lineno=None):
        """
        Parses the given line of text to find the names for the host,
        the type of key, and the key data. The line is expected to be in the
        format used by the openssh known_hosts file.

        Lines are expected to not have leading or trailing whitespace.
        We don't bother to check for comments or empty lines.  All of
        that should be taken care of before sending the line to us.

        @param line: a line from an OpenSSH known_hosts file
        @type line: str
        """
        log = get_logger('paramiko.hostkeys')
        fields = line.split(' ')
        if len(fields) < 3:
            # Bad number of fields
            log.info("Not enough fields found in known_hosts in line %s (%r)" %
                     (lineno, line))
            return None
        fields = fields[:3]

        names, keytype, key = fields
        names = names.split(',')

        # Decide what kind of key we're looking at and create an object
        # to hold it accordingly.
        try:
            if keytype == 'ssh-rsa':
                key = RSAKey(data=base64.decodebytes(key.encode()))
            elif keytype == 'ssh-dss':
                key = DSSKey(data=base64.decodebytes(key.encode()))
            elif keytype == 'ecdsa-sha2-nistp256':
                key = ECDSAKey(data=base64.decodebytes(key.encode()))
            else:
                log.info("Unable to handle key of type %s" % (keytype,))
                return None
        except binascii.Error as e:
            raise InvalidHostKey(line, e)

        return cls(names, key)
开发者ID:chuckds,项目名称:paramiko,代码行数:43,代码来源:hostkeys.py


注:本文中的paramiko.rsakey.RSAKey.encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。