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


Python DSA.gen_params方法代码示例

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


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

示例1: generate_dsa_key_pair

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import gen_params [as 别名]
def generate_dsa_key_pair(bits=1024):
    dsa = DSA.gen_params(1024, lambda x:None)
    dsa.gen_key()
    pub = BIO.MemoryBuffer()
    dsa.save_pub_key_bio(pub)
    priv = BIO.MemoryBuffer()
    dsa.save_key_bio(priv, cipher=None)
    return dsa, priv.read(), pub.read()
开发者ID:imbaczek,项目名称:numbex,代码行数:10,代码来源:crypto.py

示例2: test_genparam_setparam_genkey

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import gen_params [as 别名]
 def test_genparam_setparam_genkey(self):
     dsa = DSA.gen_params(1024, self.callback)
     assert len(dsa) == 1024
     p = dsa.p
     q = dsa.q
     g = dsa.g
     dsa2 = DSA.set_params(p,q,g)
     assert not dsa2.check_key()
     dsa2.gen_key()
     assert dsa2.check_key()
     r,s = dsa2.sign(self.data)
     assert dsa2.verify(self.data, r, s)
开发者ID:Hypernode,项目名称:M2Crypto,代码行数:14,代码来源:test_dsa.py

示例3: test_pub_key_from_params

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import gen_params [as 别名]
 def test_pub_key_from_params(self):
     dsa = DSA.gen_params(1024, self.callback)
     dsa.gen_key()
     assert len(dsa) == 1024
     p = dsa.p
     q = dsa.q
     g = dsa.g
     pub = dsa.pub
     dsa2 = DSA.pub_key_from_params(p,q,g,pub)
     assert dsa2.check_key()
     r,s = dsa.sign(self.data)
     assert dsa2.verify(self.data, r, s)
开发者ID:appknox,项目名称:m2crypto,代码行数:14,代码来源:test_dsa.py

示例4: createKey

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import gen_params [as 别名]
 def createKey(self, cipher, length, callback, parent=None):
     key = None
     if cipher == "RSA":
         exp = 65537
         print ("Create RSA key with key length %d bits\n" % length)
         key = RSA.gen_key(length, exp, callback)
     elif cipher == "DSA":
         print ("Create DSA key with key length %d bits\n" % length)
         dsa = DSA.gen_params(length, callback)
         dsa.gen_key()
         key = dsa
     if parent != None:
         parent.finishedGeneration(key)
     return key
开发者ID:kichkasch,项目名称:ioids,代码行数:16,代码来源:KeyGenCore.py

示例5: _generate_keypair

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import gen_params [as 别名]
def _generate_keypair(password=None):
    dsa = DSA.gen_params(1024, os.urandom)

    mem_pub = BIO.MemoryBuffer()
    mem_private = BIO.MemoryBuffer()

    dsa.gen_key()
    if password is None:
        dsa.save_key_bio(mem_private, cipher=None)
    else:
        dsa.save_key_bio(mem_private, callback=lambda _: password)

    private_key = mem_private.getvalue()

    dsa.save_pub_key_bio(mem_pub)

    public_key = _run_ssh_on_string(SSH_KEYGEN_COMMAND + " -f %s -i -m PKCS8",
                                    mem_pub.getvalue())[:-1]
    return {"public": public_key, "private": private_key}
开发者ID:allisonheath,项目名称:novacluster,代码行数:21,代码来源:novacluster.py

示例6: main

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import gen_params [as 别名]
def main(keylen, hashalg):
    global dsa, dgst     # this exists ONLY for speed testing
    
    Rand.load_file('randpool.dat', -1) 
        
    pvtkeyfilename = 'DSA%dpvtkey.pem' % (keylen)
    pubkeyfilename = 'DSA%dpubkey.pem' % (keylen)  
    
    if makenewkey:
        print '  making and saving a new key'
        dsa = DSA.gen_params(keylen)
        dsa.gen_key()
        dsa.save_key(pvtkeyfilename, None )  # no pswd callback
        dsa.save_pub_key(pubkeyfilename)
    else:
        print '  loading an existing key'
        dsa = DSA.load_key(pvtkeyfilename)
    print '  dsa key length:', len(dsa)
    
    if not dsa.check_key():
        raise 'key is not initialised'
        
    if showpubkey:
        dsa_pub = dsa.pub
        pub_pem = base64.encodestring(dsa_pub)
        print '  PEM public key is: \n',pub_pem

    # since we are testing signing and verification, let's not 
    # be fussy about the digest.  Just make one.
    md = EVP.MessageDigest(hashalg)
    md.update('can you spell subliminal channel?')
    dgst = md.digest()
    print '  hash algorithm: %s' % hashalg
    if showdigest:
        print '  %s digest: \n%s' % (hashalg, base64.encodestring(dgst))
    
    test(dsa, dgst)
#    test_asn1(dsa, dgst)
    test_speed(dsa, dgst)
    Rand.save_file('randpool.dat')
开发者ID:0xkag,项目名称:M2Crypto,代码行数:42,代码来源:dsa_bench.py

示例7: generate_keypair

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import gen_params [as 别名]
    def generate_keypair(self, password=None):
        ''' Generate a 1024 bit DSA key.  Someday they will be password
        protected.
        returns public key, private key '''

        dsa = DSA.gen_params(1024, os.urandom)

        mem_pub = BIO.MemoryBuffer()
        mem_private = BIO.MemoryBuffer()

        dsa.gen_key()
        if password is None:
            dsa.save_key_bio(mem_private, cipher=None)
        else:
            dsa.save_key_bio(mem_private, callback=lambda _: password)

        private_key = mem_private.getvalue()

        dsa.save_pub_key_bio(mem_pub)

        public_key = self._pubkey_from_private(mem_pub.getvalue())

        return public_key, private_key
开发者ID:LabAdvComp,项目名称:tukey_middleware,代码行数:25,代码来源:login_keypairs.py

示例8:

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import gen_params [as 别名]
#!/usr/bin/python

from M2Crypto import DSA

dsainstance = DSA.gen_params(512)

print dsainstance
开发者ID:kichkasch,项目名称:ioids,代码行数:9,代码来源:m2crypto_test.py


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