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


Python crypto.TYPE_DSA属性代码示例

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


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

示例1: test_failedGeneration

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def test_failedGeneration(self):
        """
        :py:meth:`PKeyType.generate_key` takes two arguments, the first giving the key
        type as one of :py:data:`TYPE_RSA` or :py:data:`TYPE_DSA` and the second giving the
        number of bits to generate.  If an invalid type is specified or
        generation fails, :py:exc:`Error` is raised.  If an invalid number of bits is
        specified, :py:exc:`ValueError` or :py:exc:`Error` is raised.
        """
        key = PKey()
        self.assertRaises(TypeError, key.generate_key)
        self.assertRaises(TypeError, key.generate_key, 1, 2, 3)
        self.assertRaises(TypeError, key.generate_key, "foo", "bar")
        self.assertRaises(Error, key.generate_key, -1, 0)

        self.assertRaises(ValueError, key.generate_key, TYPE_RSA, -1)
        self.assertRaises(ValueError, key.generate_key, TYPE_RSA, 0)

        # XXX RSA generation for small values of bits is fairly buggy in a wide
        # range of OpenSSL versions.  I need to figure out what the safe lower
        # bound for a reasonable number of OpenSSL versions is and explicitly
        # check for that in the wrapper.  The failure behavior is typically an
        # infinite loop inside OpenSSL.

        # self.assertRaises(Error, key.generate_key, TYPE_RSA, 2)

        # XXX DSA generation seems happy with any number of bits.  The DSS
        # says bits must be between 512 and 1024 inclusive.  OpenSSL's DSA
        # generator doesn't seem to care about the upper limit at all.  For
        # the lower limit, it uses 512 if anything smaller is specified.
        # So, it doesn't seem possible to make generate_key fail for
        # TYPE_DSA with a bits argument which is at least an int.

        # self.assertRaises(Error, key.generate_key, TYPE_DSA, -7) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:35,代码来源:test_crypto.py

示例2: test_dsaGeneration

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def test_dsaGeneration(self):
        """
        :py:meth:`PKeyType.generate_key` generates a DSA key when passed
        :py:data:`TYPE_DSA` as a type and a reasonable number of bits.
        """
        # 512 is a magic number.  The DSS (Digital Signature Standard)
        # allows a minimum of 512 bits for DSA.  DSA_generate_parameters
        # will silently promote any value below 512 to 512.
        bits = 512
        key = PKey()
        key.generate_key(TYPE_DSA, bits)
        # self.assertEqual(key.type(), TYPE_DSA)
        # self.assertEqual(key.bits(), bits)
        # self.assertRaises(TypeError, key.check) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:16,代码来源:test_crypto.py

示例3: test_regeneration

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def test_regeneration(self):
        """
        :py:meth:`PKeyType.generate_key` can be called multiple times on the same
        key to generate new keys.
        """
        key = PKey()
        for type, bits in [(TYPE_RSA, 512), (TYPE_DSA, 576)]:
             key.generate_key(type, bits)
             self.assertEqual(key.type(), type)
             self.assertEqual(key.bits(), bits) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:12,代码来源:test_crypto.py

示例4: inspect

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def inspect(self):
        t = self.original.type()
        if t == crypto.TYPE_RSA:
            ts = 'RSA'
        elif t == crypto.TYPE_DSA:
            ts = 'DSA'
        else:
            ts = '(Unknown Type!)'
        L = (self.original.bits(), ts, self.keyHash())
        return '%s-bit %s Key Pair with Hash: %s' % L 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:_sslverify.py

示例5: create_dsa_keypair

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def create_dsa_keypair(bits=2048):
    pkey = crypto.PKey()
    pkey.generate_key(crypto.TYPE_DSA, bits)
    return PrivateKey(_key=pkey) 
开发者ID:kdart,项目名称:pycopia,代码行数:6,代码来源:certs.py

示例6: generate_dsa

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def generate_dsa():
    keys = []
    for i in range(100):
        key = PKey()
        key.generate_key(TYPE_DSA, 512)
        keys.append(key) 
开发者ID:pyca,项目名称:pyopenssl,代码行数:8,代码来源:thread-key-gen.py

示例7: test_failed_generation

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def test_failed_generation(self):
        """
        `PKey.generate_key` takes two arguments, the first giving the key type
        as one of `TYPE_RSA` or `TYPE_DSA` and the second giving the number of
        bits to generate.  If an invalid type is specified or generation fails,
        `Error` is raised.  If an invalid number of bits is specified,
        `ValueError` or `Error` is raised.
        """
        key = PKey()
        with pytest.raises(TypeError):
            key.generate_key("foo", "bar")
        with pytest.raises(Error):
            key.generate_key(-1, 0)

        with pytest.raises(ValueError):
            key.generate_key(TYPE_RSA, -1)
        with pytest.raises(ValueError):
            key.generate_key(TYPE_RSA, 0)

        with pytest.raises(TypeError):
            key.generate_key(TYPE_RSA, object())

        # XXX RSA generation for small values of bits is fairly buggy in a wide
        # range of OpenSSL versions.  I need to figure out what the safe lower
        # bound for a reasonable number of OpenSSL versions is and explicitly
        # check for that in the wrapper.  The failure behavior is typically an
        # infinite loop inside OpenSSL.

        # with pytest.raises(Error):
        #     key.generate_key(TYPE_RSA, 2)

        # XXX DSA generation seems happy with any number of bits.  The DSS
        # says bits must be between 512 and 1024 inclusive.  OpenSSL's DSA
        # generator doesn't seem to care about the upper limit at all.  For
        # the lower limit, it uses 512 if anything smaller is specified.
        # So, it doesn't seem possible to make generate_key fail for
        # TYPE_DSA with a bits argument which is at least an int.

        # with pytest.raises(Error):
        #     key.generate_key(TYPE_DSA, -7) 
开发者ID:pyca,项目名称:pyopenssl,代码行数:42,代码来源:test_crypto.py

示例8: test_dsa_generation

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def test_dsa_generation(self):
        """
        `PKey.generate_key` generates a DSA key when passed `TYPE_DSA` as a
        type and a reasonable number of bits.
        """
        # 512 is a magic number.  The DSS (Digital Signature Standard)
        # allows a minimum of 512 bits for DSA.  DSA_generate_parameters
        # will silently promote any value below 512 to 512.
        bits = 512
        key = PKey()
        key.generate_key(TYPE_DSA, bits)
        assert key.type() == TYPE_DSA
        assert key.bits() == bits
        with pytest.raises(TypeError):
            key.check() 
开发者ID:pyca,项目名称:pyopenssl,代码行数:17,代码来源:test_crypto.py

示例9: test_regeneration

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def test_regeneration(self):
        """
        `PKey.generate_key` can be called multiple times on the same key to
        generate new keys.
        """
        key = PKey()
        for type, bits in [(TYPE_RSA, 512), (TYPE_DSA, 576)]:
            key.generate_key(type, bits)
            assert key.type() == type
            assert key.bits() == bits 
开发者ID:pyca,项目名称:pyopenssl,代码行数:12,代码来源:test_crypto.py

示例10: test_dump_privatekey_not_rsa_key

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def test_dump_privatekey_not_rsa_key(self):
        """
        `dump_privatekey` raises `TypeError` if called with a key that is
        not RSA.
        """
        key = PKey()
        key.generate_key(TYPE_DSA, 512)
        with pytest.raises(TypeError):
            dump_privatekey(FILETYPE_TEXT, key) 
开发者ID:pyca,项目名称:pyopenssl,代码行数:11,代码来源:test_crypto.py

示例11: createKeyPair

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def createKeyPair(type, bits):
    """
    Create a public/private key pair.
    Arguments: type - Key type, must be one of TYPE_RSA and TYPE_DSA
               bits - Number of bits to use in the key
    Returns:   The public/private key pair in a PKey object
    """
    pkey = crypto.PKey()
    pkey.generate_key(type, bits)
    return pkey 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:12,代码来源:certgen.py

示例12: _create_account_key

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def _create_account_key(self):
        account_key = crypto.PKey()

        if self.type == 'RSA':
            crypto_type = crypto.TYPE_RSA
        else:
            crypto_type = crypto.TYPE_DSA

        try:
            LOG.info('[global] Generating account key: %s \
                     (type: %s, size: %s)' %
                     (self.account_key_name, self.type, self.size))
            account_key.generate_key(crypto_type, self.size)
        except (TypeError, ValueError):
            raise

        try:
            LOG.debug('[global] Writting account key: %s/private/%s' %
                      (self.path, self.account_key_name))
            accountkey_file = os.open('%s/private/%s' %
                                      (self.path, self.account_key_name),
                                      os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
                                      0o600)
            os.write(accountkey_file,
                     crypto.dump_privatekey(crypto.FILETYPE_PEM, account_key))
            os.close(accountkey_file)
        except IOError:
            try:
                os.remove('%s/private/%s.key' %
                          (self.path, self.account_key_name))
            except OSError:
                pass
            raise 
开发者ID:Spredzy,项目名称:lecm,代码行数:35,代码来源:certificate.py

示例13: _create_private_key

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import TYPE_DSA [as 别名]
def _create_private_key(self):
        private_key = crypto.PKey()

        if self.type == 'RSA':
            crypto_type = crypto.TYPE_RSA
        else:
            crypto_type = crypto.TYPE_DSA

        try:
            LOG.info('[%s] Generating private key (type: %s, size: %s)' %
                     (self.name, self.type, self.size))
            private_key.generate_key(crypto_type, self.size)
        except (TypeError, ValueError):
            raise

        try:
            LOG.debug('[%s] Writting private key: %s/private/%s.key' %
                      (self.name, self.path, self.name))
            privatekey_file = os.open('%s/private/%s.key' %
                                      (self.path, self.name),
                                      os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
                                      0o600)
            os.write(privatekey_file,
                     crypto.dump_privatekey(crypto.FILETYPE_PEM, private_key))
            os.close(privatekey_file)
        except IOError:
            try:
                os.remove('%s/private/%s.key' % (self.path, self.name))
            except OSError:
                pass
            raise 
开发者ID:Spredzy,项目名称:lecm,代码行数:33,代码来源:certificate.py


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