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


Python Key.public方法代码示例

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


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

示例1: getKeyPair

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import public [as 别名]
def getKeyPair(pubkeyfile, privkeyfile):
    """
    This function looks for RSA keypair files in the current directory. If they
    do not exist, the keypair is created.
    """

    if not (os.path.exists(pubkeyfile) and os.path.exists(privkeyfile)):
        # No keypair exists. Generate a new RSA keypair
        print("  Generating SSH RSA keypair ...", end=' ')
        from Crypto.PublicKey import RSA

        KEY_LENGTH = 1024
        rsaKey = Key(RSA.generate(KEY_LENGTH))
        publicKeyString = rsaKey.public().toString(type="OPENSSH")
        privateKeyString = rsaKey.toString(type="OPENSSH")

        # save keys for the future.
        file(pubkeyfile, 'w+b').write(publicKeyString)
        file(privkeyfile, 'w+b').write(privateKeyString)
        print(" done.")
    else:
        publicKeyString = file(pubkeyfile).read()
        privateKeyString = file(privkeyfile).read()

    return Key.fromString(publicKeyString), Key.fromString(privateKeyString)
开发者ID:325975,项目名称:evennia,代码行数:27,代码来源:ssh.py

示例2: getKeyPair

# 需要导入模块: from twisted.conch.ssh.keys import Key [as 别名]
# 或者: from twisted.conch.ssh.keys.Key import public [as 别名]
def getKeyPair(pubkeyfile, privkeyfile):
    """
    This function looks for RSA keypair files in the current directory. If they
    do not exist, the keypair is created.
    """

    if not (os.path.exists(pubkeyfile) and os.path.exists(privkeyfile)):
        # No keypair exists. Generate a new RSA keypair
        from Crypto.PublicKey import RSA

        rsa_key = Key(RSA.generate(_KEY_LENGTH))
        public_key_string = rsa_key.public().toString(type="OPENSSH")
        private_key_string = rsa_key.toString(type="OPENSSH")

        # save keys for the future.
        with open(privkeyfile, 'wt') as pfile:
            pfile.write(private_key_string)
            print("Created SSH private key in '{}'".format(_PRIVATE_KEY_FILE))
        with open(pubkeyfile, 'wt') as pfile:
            pfile.write(public_key_string)
            print("Created SSH public key in '{}'".format(_PUBLIC_KEY_FILE))
    else:
        with open(pubkeyfile) as pfile:
            public_key_string = pfile.read()
        with open(privkeyfile) as pfile:
            private_key_string = pfile.read()

    return Key.fromString(public_key_string), Key.fromString(private_key_string)
开发者ID:BlauFeuer,项目名称:evennia,代码行数:30,代码来源:ssh.py


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