• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python crypto.generate_key_pair函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nova.crypto.generate_key_pair函数的典型用法代码示例。如果您正苦于以下问题:Python generate_key_pair函数的具体用法?Python generate_key_pair怎么用?Python generate_key_pair使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_generate_key_pair_1024_bits

 def test_generate_key_pair_1024_bits(self):
     bits = 1024
     (private_key, public_key, fingerprint) = crypto.generate_key_pair(bits)
     pub_bytes = public_key.encode('utf-8')
     pkey = serialization.load_ssh_public_key(
         pub_bytes, backends.default_backend())
     self.assertEqual(bits, pkey.key_size)
开发者ID:B3n0n3,项目名称:nova,代码行数:7,代码来源:test_crypto.py


示例2: generate_key_pair

    def generate_key_pair(self, user, key_name):
        """Generates a key pair for a user

        Generates a public and private key, stores the public key using the
        key_name, and returns the private key and fingerprint.

        @type user: User or uid
        @param user: User for which to create key pair.

        @type key_name: str
        @param key_name: Name to use for the generated KeyPair.

        @rtype: tuple (private_key, fingerprint)
        @return: A tuple containing the private_key and fingerprint.
        """
        # NOTE(vish): generating key pair is slow so check for legal
        #             creation before creating keypair
        uid = User.safe_id(user)
        with self.driver() as drv:
            if not drv.get_user(uid):
                raise exception.NotFound("User %s doesn't exist" % user)
            if drv.get_key_pair(uid, key_name):
                raise exception.Duplicate("The keypair %s already exists"
                                          % key_name)
        private_key, public_key, fingerprint = crypto.generate_key_pair()
        self.create_key_pair(uid, key_name, public_key, fingerprint)
        return private_key, fingerprint
开发者ID:ChristopherMacGown,项目名称:my-nova,代码行数:27,代码来源:manager.py


示例3: _gen_key

 def _gen_key(self):
     """
     Generate a key
     """
     private_key, public_key, fingerprint = crypto.generate_key_pair()
     return {'private_key': private_key,
             'public_key': public_key,
             'fingerprint': fingerprint}
开发者ID:emonty,项目名称:nova,代码行数:8,代码来源:keypairs.py


示例4: test_generate_key_pair_2048_bits

 def test_generate_key_pair_2048_bits(self):
     (private_key, public_key, fingerprint) = crypto.generate_key_pair()
     raw_pub = public_key.split(' ')[1]
     if six.PY3:
         raw_pub = raw_pub.encode('ascii')
     raw_pub = base64.b64decode(raw_pub)
     pkey = paramiko.rsakey.RSAKey(None, raw_pub)
     self.assertEqual(2048, pkey.get_bits())
开发者ID:jeffrey4l,项目名称:nova,代码行数:8,代码来源:test_crypto.py


示例5: is_valid_appliance

def is_valid_appliance():

    nova_home = get_nova_home()
    '    Change to user nova    '
    LOG.debug(_('Executing as ' + whoami()))
    if whoami() == 'root':
        change_user('nova')

    if whoami() != 'nova':
        LOG.debug(_('nova does not exists'))
        return False

    if os.path.exists(nova_home) is False:
        '''
        nova does not exists.Exiting now
        #todo : sys.exit()
        '''
        return False

    #    Check if the id_rsa and id_rsa.pub already exists.
    #    If they exist don't generate new keys"

    if not os.path.exists(os.path.join(nova_home + '/.ssh/')):
        os.makedirs(os.path.join(nova_home + '/.ssh/'), 01700)

    if os.path.isfile(
        os.path.join(nova_home + '/.ssh/id_rsa.pub')) is False and \
            os.path.isfile(os.path.join(nova_home + '/.ssh/id_rsa')) is False:
        '    Generate id_rsa and id_rsa.pub files. '
        '    This will be stored in $NOVAHOME/.ssh/ '
        '    use nova'
        private_key, public_key, _fingerprint = crypto.generate_key_pair()
        pub_file = open(os.path.join(nova_home + '/.ssh/id_rsa.pub'), "w+")
        pub_file.writelines(public_key)
        pub_file.close()

        private_file = open(os.path.join(nova_home + '/.ssh/id_rsa'), "w+")
        private_file.writelines(private_key)
        private_file.close()

        os.chmod(os.path.join(nova_home + '/.ssh/id_rsa.pub'), 0700)
        os.chmod(os.path.join(nova_home + '/.ssh/id_rsa'), 0700)
        # os.popen('ssh-keygen -t rsa', 'w').write(''' ''')
        LOG.debug(_('created new id_rsa and id_rsa.pub'))
    else:

        LOG.debug(_('id_rsa and id_rsa.pub exists'))

    '  create known_hosts file if it does not exist'
    if os.path.isfile(os.path.join(nova_home + '/.ssh/known_hosts')) is False:
        filename = os.path.join(nova_home + '/.ssh/known_hosts')
        handle = open(filename, 'w')
        handle.close
        os.chmod(os.path.join(nova_home + '/.ssh/known_hosts'), 0700)

    return True
开发者ID:jessegonzalez,项目名称:healthnmon,代码行数:56,代码来源:ssh_configuration.py


示例6: test_generate_key_pair_mocked_private_key

    def test_generate_key_pair_mocked_private_key(self):
        keyin = six.StringIO()
        keyin.write(self.rsa_prv)
        keyin.seek(0)
        key = paramiko.RSAKey.from_private_key(keyin)

        with mock.patch.object(crypto, 'generate_key') as mock_generate:
            mock_generate.return_value = key
            (private_key, public_key, fingerprint) = crypto.generate_key_pair()
            self.assertEqual(self.rsa_pub, public_key)
            self.assertEqual(self.rsa_fp, fingerprint)
开发者ID:B3n0n3,项目名称:nova,代码行数:11,代码来源:test_crypto.py


示例7: generate_key_pair

 def generate_key_pair(self, user, key_name):
     # generating key pair is slow so delay generation
     # until after check
     user = User.safe_id(user)
     with LDAPWrapper() as conn:
         if not conn.user_exists(user):
             raise exception.NotFound("User %s doesn't exist" % user)
         if conn.key_pair_exists(user, key_name):
             raise exception.Duplicate("The keypair %s already exists" % key_name)
     private_key, public_key, fingerprint = crypto.generate_key_pair()
     self.create_key_pair(User.safe_id(user), key_name, public_key, fingerprint)
     return private_key, fingerprint
开发者ID:sorenh,项目名称:cc,代码行数:12,代码来源:users.py


示例8: test_generate_key_pair

    def test_generate_key_pair(self):
        (private_key, public_key, fingerprint) = crypto.generate_key_pair()
        raw_pub = public_key.split(' ')[1].decode('base64')
        pkey = paramiko.rsakey.RSAKey(None, raw_pub)
        self.assertEqual(2048, pkey.get_bits())

        bits = 4096
        (private_key, public_key, fingerprint) = crypto.generate_key_pair(bits)
        raw_pub = public_key.split(' ')[1].decode('base64')
        pkey = paramiko.rsakey.RSAKey(None, raw_pub)
        self.assertEqual(bits, pkey.get_bits())

        keyin = StringIO.StringIO()
        keyin.write(self.rsa_prv)
        keyin.seek(0)
        key = paramiko.RSAKey.from_private_key(keyin)

        with mock.patch.object(paramiko.RSAKey, 'generate') as mock_generate:
            mock_generate.return_value = key
            (private_key, public_key, fingerprint) = crypto.generate_key_pair()
            self.assertEqual(self.rsa_pub, public_key)
            self.assertEqual(self.rsa_fp, fingerprint)
开发者ID:arunagummalla,项目名称:nova,代码行数:22,代码来源:test_crypto.py


示例9: generate_key_pair

 def generate_key_pair(self, uid, key_name):
     # generating key pair is slow so delay generation
     # until after check
     with LDAPWrapper() as conn:
         if not conn.user_exists(uid):
             raise UserError("User " + uid + " doesn't exist")
         if conn.key_pair_exists(uid, key_name):
             raise InvalidKeyPair("The keypair '" +
                         key_name +
                         "' already exists.",
                         "Duplicate")
     private_key, public_key, fingerprint = crypto.generate_key_pair()
     self.create_key_pair(uid, key_name, public_key, fingerprint)
     return private_key, fingerprint
开发者ID:joshuamckenty,项目名称:pinet,代码行数:14,代码来源:users.py


示例10: _gen_key

    def _gen_key(self, context, user_id, key_name):
        """Generate a key

        This is a module level method because it is slow and we need to defer
        it into a process pool."""
        # NOTE(vish): generating key pair is slow so check for legal
        #             creation before creating key_pair
        try:
            db.key_pair_get(context, user_id, key_name)
            raise exception.KeyPairExists(key_name=key_name)
        except exception.NotFound:
            pass
        private_key, public_key, fingerprint = crypto.generate_key_pair()
        key = {}
        key['user_id'] = user_id
        key['name'] = key_name
        key['public_key'] = public_key
        key['fingerprint'] = fingerprint
        db.key_pair_create(context, key)
        return {'private_key': private_key, 'fingerprint': fingerprint}
开发者ID:mgius,项目名称:openstackx,代码行数:20,代码来源:admin.py


示例11: _gen_key

 def _gen_key(self):
     """
     Generate a key
     """
     private_key, public_key, fingerprint = crypto.generate_key_pair()
     return {"private_key": private_key, "public_key": public_key, "fingerprint": fingerprint}
开发者ID:hiteshwadekar,项目名称:nova,代码行数:6,代码来源:keypairs.py


示例12: test_generate_key_pair_1024_bits

 def test_generate_key_pair_1024_bits(self):
     bits = 1024
     (private_key, public_key, fingerprint) = crypto.generate_key_pair(bits)
     raw_pub = base64.b64decode(public_key.split(' ')[1])
     pkey = paramiko.rsakey.RSAKey(None, raw_pub)
     self.assertEqual(bits, pkey.get_bits())
开发者ID:jeffrey4l,项目名称:nova,代码行数:6,代码来源:test_crypto.py


示例13: test_generate_key_pair_2048_bits

 def test_generate_key_pair_2048_bits(self):
     (private_key, public_key, fingerprint) = crypto.generate_key_pair()
     raw_pub = public_key.split(' ')[1].decode('base64')
     pkey = paramiko.rsakey.RSAKey(None, raw_pub)
     self.assertEqual(2048, pkey.get_bits())
开发者ID:Milstein,项目名称:nova,代码行数:5,代码来源:test_crypto.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python crypto.generate_x509_cert函数代码示例发布时间:2022-05-27
下一篇:
Python crypto.fetch_ca函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap