本文整理汇总了Python中paramiko.DSSKey.generate方法的典型用法代码示例。如果您正苦于以下问题:Python DSSKey.generate方法的具体用法?Python DSSKey.generate怎么用?Python DSSKey.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko.DSSKey
的用法示例。
在下文中一共展示了DSSKey.generate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keygen
# 需要导入模块: from paramiko import DSSKey [as 别名]
# 或者: from paramiko.DSSKey import generate [as 别名]
def keygen(keyname, keytype, bits, passphrase):
""" Generates a private/public keypair and returns it.
"""
# Initialisations and sanity checks
retval = {"generation_messages": "", "generation_status": "success"}
if keytype not in ['rsa', 'dsa']:
retval["generation_messages"] = _("Invalid keytype: %s" % keytype)
retval["generation_status"] = "error"
if bits not in [1024, 2048, 3072, 4096]:
retval["generation_messages"] = \
_("Invalid number of bits: %s" % bits)
retval["generation_status"] = "error"
if keytype == "dsa" and bits != 1024:
retval["generation_messages"] = _("DSA only supports 1024 bits.")
retval["generation_status"] = "error"
if retval["generation_status"] == "success":
# Generate private key
if keytype == "rsa":
key = RSAKey.generate(bits=bits)
typestring = "ssh-rss "
else:
key = DSSKey.generate(bits=bits)
typestring = "ssh-dss "
# Format public key
keystring = "%s %s %s" % (
typestring,
key.get_base64(),
keyname
)
retval["public_key"] = keystring
tmp = StringIO.StringIO()
if passphrase == "":
passphrase = None
key.write_private_key(tmp, passphrase)
retval["private_key"] = tmp.getvalue()
return retval
示例2: testRSAKey
# 需要导入模块: from paramiko import DSSKey [as 别名]
# 或者: from paramiko.DSSKey import generate [as 别名]
def testRSAKey(self):
with self.get_session() as session:
rpkey = pRSAKey.generate(256)
rkey = Key.build_from_paramiko_key('rsa', rpkey)
nrkey = rkey.get_paramiko_key()
self.assertEqual(rpkey.e, nrkey.e)
self.assertEqual(rpkey.n, nrkey.n)
self.assertEqual(nrkey, rpkey)
dpkey = DSSKey.generate(1024)
dkey = Key.build_from_paramiko_key('dsa', dpkey)
self.assertEqual(dpkey, dkey.get_paramiko_key())
session.add(rkey)
session.add(dkey)
session.commit()
qrkey = session.query(Key).filter(Key.name=='rsa')[0]
self.assertTrue(isinstance(qrkey,RSAKey))
pepe = session.query(Computer).filter_by(name='test_computer')[0]
pepe.key = qrkey
session.commit()
pepe = session.query(Computer).filter_by(name='test_computer')[0]
self.assertEqual(pepe.key.get_paramiko_key(), rpkey)
示例3: test_B_generate_dss
# 需要导入模块: from paramiko import DSSKey [as 别名]
# 或者: from paramiko.DSSKey import generate [as 别名]
def test_B_generate_dss(self):
key = DSSKey.generate(1024)
msg = key.sign_ssh_data(rng, 'jerri blank')
msg.rewind()
self.assert_(key.verify_ssh_sig('jerri blank', msg))
示例4: test_B_generate_dss
# 需要导入模块: from paramiko import DSSKey [as 别名]
# 或者: from paramiko.DSSKey import generate [as 别名]
def test_B_generate_dss(self):
key = DSSKey.generate(1024)
msg = key.sign_ssh_data(b"jerri blank")
msg.rewind()
self.assertTrue(key.verify_ssh_sig(b"jerri blank", msg))