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


Python M2Crypto.DSA类代码示例

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


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

示例1: test_verify_fail2

 def test_verify_fail2(self):
     dsa = DSA.load_key(self.privkey)
     r, s = dsa.sign(self.data)
     dsa2 = DSA.load_params(self.param)
     assert not dsa2.check_key()
     with self.assertRaises(AssertionError):
         dsa2.verify(self.data, r, s)
开发者ID:appknox,项目名称:m2crypto,代码行数:7,代码来源:test_dsa.py

示例2: test_pub_verify

 def test_pub_verify(self):
     dsa = DSA.load_key(self.privkey)
     r, s = dsa.sign(self.data)
     dsapub = DSA.load_pub_key(self.pubkey)
     assert dsapub.check_key()
     assert dsapub.verify(self.data, r, s)
     self.assertRaises(DSA.DSAError, dsapub.sign)
开发者ID:Hypernode,项目名称:M2Crypto,代码行数:7,代码来源:test_dsa.py

示例3: test_pub_key_from_params

 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,代码行数:12,代码来源:test_dsa.py

示例4: test_genparam_setparam_genkey

 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,代码行数:12,代码来源:test_dsa.py

示例5: _dnskey_to_dsa

def _dnskey_to_dsa(key):
    # get T
    t, = struct.unpack(b'B',key[0])
    offset = 1

    # get Q
    new_offset = offset+20
    q = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get P
    new_offset = offset+64+(t<<3)
    p = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get G
    new_offset = offset+64+(t<<3)
    g = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get Y
    new_offset = offset+64+(t<<3)
    y = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # create the DSA public key
    return DSA.pub_key_from_params(p,q,g,y)
开发者ID:xbolshe,项目名称:dnsviz,代码行数:27,代码来源:crypto.py

示例6: generatedata

def generatedata(n, owner="freeconet", keyfile="freeconet.priv.pem"):
    start = 48600000000
    end = 48699999999
    thissip = "sip.freeconet.pl"
    prevsip = "new.freeconet.pl"
    thisdate = datetime.datetime(2009, 2, 14, 12).isoformat()
    prevdate = datetime.datetime(2009, 2, 15, 9).isoformat()
    from random import randrange

    # no duplicates
    points = list(set(randrange(start, end) for i in xrange(n)))
    points.sort()
    first = ["+%s" % start, "+%s" % points[0], thissip, owner, thisdate]
    from M2Crypto import DSA

    dsa = DSA.load_key(keyfile)
    first.append(crypto.sign_record(dsa, *first))
    data = [first]
    for i in xrange(n - 1):
        print i, i + 1, len(points), points[i]
        s = points[i]
        e = points[i + 1] - 1
        thissip, prevsip = prevsip, thissip
        thisdate, prevdate = prevdate, thisdate
        r = ["+%s" % s, "+%s" % e, thissip, owner, thisdate]
        r.append(crypto.sign_record(dsa, *r))
        data.append(r)
    return data
开发者ID:imbaczek,项目名称:numbex,代码行数:28,代码来源:scripts.py

示例7: parse_pub_key

def parse_pub_key(pubstr):
    if not isinstance(pubstr, str):
        raise TypeError('str argument required')
    if not pubstr.startswith('-----BEGIN PUBLIC KEY-----'):
        raise ValueError("public key didn't start with '-----BEGIN PUBLIC KEY-----'")
    mem = BIO.MemoryBuffer(pubstr)
    return DSA.load_pub_key_bio(mem)
开发者ID:imbaczek,项目名称:numbex,代码行数:7,代码来源:crypto.py

示例8: generateSign

 def generateSign(self):
   message = self.toRaw()
   md = EVP.MessageDigest('sha1')
   md.update(message)        
   digest = md.final()
   dsa = DSA.load_key("keys/dsa_priv_ms.pem")
   self.signature = dsa.sign(digest)
   return
开发者ID:diegomonterob,项目名称:sdn_lisp_map_register,代码行数:8,代码来源:ServiceACK.py

示例9: test_loadkey

 def test_loadkey(self):
     dsa = DSA.load_key(self.privkey)
     self.assertEqual(len(dsa), 1024)
     with self.assertRaises(AttributeError):
         getattr(dsa, 'foobar')
     for k in ('p', 'q', 'g', 'priv', 'pub'):
         with self.assertRaises(DSA.DSAError):
             setattr(dsa, k, 1)
开发者ID:appknox,项目名称:m2crypto,代码行数:8,代码来源:test_dsa.py

示例10: parse_priv_key

def parse_priv_key(privstr):
    if not isinstance(privstr, str):
        raise TypeError('str argument required')
    if not privstr.startswith('-----BEGIN DSA PRIVATE KEY-----') \
            and not privstr.startswith('-----BEGIN RSA PRIVATE KEY-----'):
        raise ValueError("public key didn't start with '-----BEGIN ANY PRIVATE KEY-----'")
    mem = BIO.MemoryBuffer(privstr)
    return DSA.load_key_bio(mem)
开发者ID:imbaczek,项目名称:numbex,代码行数:8,代码来源:crypto.py

示例11: generate_dsa_key_pair

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,代码行数:8,代码来源:crypto.py

示例12: verifySign

 def verifySign(self):
   message = self.toRaw()
   md = EVP.MessageDigest('sha1')
   md.update(message)        
   digest = md.final()
   dsa = DSA.load_pub_key("keys/dsa_pub_ms.pem")
   good = dsa.verify(digest, self.signature[0],self.signature[1])
   print "*** Verifying MapReply sign ", good
   return good
开发者ID:diegomonterob,项目名称:sdn_lisp_map_register,代码行数:9,代码来源:ServiceACK.py

示例13: __init__

 def __init__(self,pub_key_Path, priv_key_Path=None ):
     ##LOAD priv_key
     try:
         if priv_key_Path is not None:
             try:
                 priv_key = RSA.load_key(priv_key_Path)
             except Exception, e:
                 priv_key = DSA.load_key(priv_key_Path)
         else :
开发者ID:b3c,项目名称:mod_auth,代码行数:9,代码来源:mod_auth.py

示例14: set_security_agent

def set_security_agent(request):
    serviceDIGEST = "user_id=%s&granted_roles=%s&timestamp=%s"
    serviceACTION = "%s/setgrantedroles?%s&sign=%s"
    Roles = ()
    serviceURL = ""
    try:
        if request.method == "POST":
            for key, value in request.POST.iteritems():
                if key == "serviceURL":
                    serviceURL = value
                elif key == "csrfmiddlewaretoken":
                    continue
                else:
                    role = Role.objects.get(name=key)
                    if not isinstance(role, roles):
                        return HttpResponse('FALSE')
                    Roles = Roles + ( key, )

            validator = URLValidator()
            try:
                validator(serviceURL)
            except Exception, e:
                return HttpResponse("Service URL is not well formed")
            granted_roles = ""
            for value in Roles:
                granted_roles += str(value) + ","
            granted_roles = granted_roles[:-1]

            serviceDIGEST = serviceDIGEST % (request.user.username, granted_roles, str(int(time.time())))
            key = DSA.load_key(settings.MOD_AUTH_PRIVTICKET)
            serviceSIGN = calculate_sign(key, serviceDIGEST)

            requestURL = serviceACTION % (serviceURL, serviceDIGEST, serviceSIGN)
            username = "test"
            password = "test"

            passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
            passman.add_password(None, requestURL, username, password)
            authhandler = urllib2.HTTPBasicAuthHandler(passman)

            opener = urllib2.build_opener(authhandler)

            urllib2.install_opener(opener)

            try:
                pagehandle = urllib2.urlopen(requestURL)
            except:
                pagehandle = urllib2.urlopen(requestURL)
            if pagehandle.code != 200:
                return HttpResponse(' Sec/Agent request refused.')

            return HttpResponse('TRUE')
    except Exception, e:
        return HttpResponse("FALSE")
开发者ID:b3c,项目名称:vphshare,代码行数:54,代码来源:views.py

示例15: main

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,代码行数:40,代码来源:dsa_bench.py


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