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


Python DSA.load_pub_key方法代码示例

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


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

示例1: test_pub_verify

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import load_pub_key [as 别名]
 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,代码行数:9,代码来源:test_dsa.py

示例2: verifySign

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import load_pub_key [as 别名]
 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,代码行数:11,代码来源:ServiceACK.py

示例3: verifySign

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import load_pub_key [as 别名]
 def verifySign(self):
   message = self.toRaw()
   print "VerSign Raw:", (":".join("{0:02x}".format(ord(c)) for c in message))
   md = EVP.MessageDigest('sha1')
   md.update(message)        
   digest = md.final()
   print "VerSign SHA1:", (":".join("{0:02x}".format(ord(c)) for c in digest))
   #print "Mask:", (":".join("{0:02x}".format(ord(c)) for c in self.mask))
   #print "Mask:", self.mask
   dsa = DSA.load_pub_key("keys/dsa_pub_xtr.pem")
   good = dsa.verify(digest, self.signature[0],self.signature[1])
   print "VerSign r:", (":".join("{0:02x}".format(ord(c)) for c in self.signature[0]))
   print "VerSign s:", (":".join("{0:02x}".format(ord(c)) for c in self.signature[1]))
   print 'VerSign: ', good
   return good
开发者ID:diegomonterob,项目名称:sdn_lisp_map_register,代码行数:17,代码来源:MapRegister.py

示例4: make_from_config

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import load_pub_key [as 别名]
 def make_from_config(cls, app, config, prefix='auth.', **kw):
     """Creates instance of AuthPubTKTMiddleware
     from dictionary-like configuration.        
     """
     keytype = config.get(prefix+'key_type', 'RSA')
     if keytype not in ('RSA', 'DSA'):
         raise ConfigError('Wrong key type: %s' % keytype)
     authpubkey = config.get(prefix+'pubkey', '')
     if not authpubkey:
         raise ConfigError('%spubkey parameter is required' % prefix)
     try:
         if keytype == 'RSA':
             pubkey = RSA.load_pub_key(authpubkey)
         else:
             pubkey = DSA.load_pub_key(authpubkey)
     except Exception, err:
         raise ConfigError('Error loading public key %s: %s' % (authpubkey, str(err)))
开发者ID:AndreyPlotnikov,项目名称:auth_pubtkt,代码行数:19,代码来源:__init__.py

示例5: make_from_config

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import load_pub_key [as 别名]
    def make_from_config(cls, app, config, prefix='auth.', **kw):
        """Creates instance of AuthPubTKTMiddleware
        from dictionary-like configuration.        
        """
        keytype = config.get(prefix+'key_type', 'RSA')
        if keytype not in ('RSA', 'DSA'):
            raise ConfigError('Wrong key type: %s' % keytype)
        authpubkey = config.get(prefix+'pubkey', '')
        if not authpubkey:
            raise ConfigError('%spubkey parameter is required' % prefix)
        try:
            if keytype == 'RSA':
                pubkey = RSA.load_pub_key(authpubkey)
            else:
                pubkey = DSA.load_pub_key(authpubkey)
        except Exception as err:
            raise ConfigError('Error loading public key %s: %s' % (authpubkey, str(err)))

        if 'required_tokens' not in kw:
            rt = config.get(prefix+'required_tokens', '').strip()
            if rt:
                kw['required_tokens'] = rt.split(',')
                
        def asbool(v, param):
            v = v.lower()
            if v in ('true', 'yes', 'on', '1'):
                v = True
            elif v in ('false', 'no', 'off', '0'):
                v = False
            else:
                ConfigError('Bad value for param %s: %s' % (params, v))
            return v

        for p, t in (('cookie_name', 'str'),
                     ('login_url', 'str')):
            k = prefix+p
            if (p not in kw) and (k in config):
                v = config[k]
                if t == 'bool':
                    v = asbool(v, k)
                kw[p] = v

        return cls(app, pubkey, **kw)
开发者ID:scivisum,项目名称:auth_pubtkt,代码行数:45,代码来源:__init__.py

示例6: make_app

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import load_pub_key [as 别名]
def make_app(global_conf,
             pub_key,
             key_type='RSA',
             cookie_name=None,
             hdr_prefix=None,
             log_name=None,
             **app_conf):
    """Paste application factory"""
    
    pub_key = RSA.load_pub_key(pub_key) if key_type == 'RSA' else DSA.load_pub_key(pub_key)
    params = {}
    if cookie_name is not None:
        params['cookie_name'] = cookie_name
    if hdr_prefix is not None:
        params['hdr_prefix'] = hdr_prefix
    if log_name is not None:
        params['log_name'] = log_name
    cache_opts = parse_cache_config_options(app_conf)
    if cache_opts.get('enabled') == True:
        cache_mgr = CacheManager(**cache_opts)
        cache = cache_mgr.get_cache('tickets_cache')
        params['cache'] = cache

    return AuthRequestApp(pub_key, **params)
开发者ID:AndreyPlotnikov,项目名称:auth_pubtkt,代码行数:26,代码来源:authrequest.py

示例7: verify_ok

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import load_pub_key [as 别名]
import sys
import logging
import os.path
from os.path import join as pjoin
import unittest
from M2Crypto import RSA, DSA
from auth_pubtkt import *


tests_dir = os.path.dirname(os.path.abspath(__file__))

rsa_priv = RSA.load_key(pjoin(tests_dir, 'rsa_priv.pem'))
rsa_pub = RSA.load_pub_key(pjoin(tests_dir, 'rsa_pub.pem'))
dsa_priv = DSA.load_key(pjoin(tests_dir, 'dsa_priv.pem'))
dsa_pub = DSA.load_pub_key(pjoin(tests_dir, 'dsa_pub.pem'))

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)


def verify_ok(pubkey, data, sig):
    return True

class ParseTicketTests(unittest.TestCase):


    def test_valid_rsa(self):

        ticket = '''uid=user1;cip=192.168.1.10;validuntil=1277190189;tokens=editor,moderator;udata=custom data;sig=W4/D/Ci2B9e60s7a1K810wPCQ3TzvlCXnAimjTVFRb6mqTFTlvdxCFmc6urC86d+8v8CtM4KsV5jsTmW/250OVkgk1PcoCz/Fvk84V5WqieWj2AVPC5DOujwy73lEeuu3/a4BfnsTagFWJZa6wGWqTEE5pULq8ZWthNXqkhXLzs='''

        fields = parse_ticket(ticket, rsa_pub)
        assert 'uid' in fields and fields['uid'] == 'user1'
开发者ID:AndreyPlotnikov,项目名称:auth_pubtkt,代码行数:33,代码来源:tests.py

示例8: __init__

# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import load_pub_key [as 别名]
    """
    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 :
                priv_key = None

            if priv_key_Path is not None and isinstance(priv_key, RSA.RSA):
                pub_key = RSA.load_pub_key(pub_key_Path)
            else:
                pub_key = DSA.load_pub_key(pub_key_Path)

        except Exception, e:
            raise ValueError('Unknown key type: %s' % self.pub_key)

        self.priv_key = priv_key
        self.pub_key =  pub_key


    def __verify_sig(self, data, sig):
        """Verify ticket signature.

        Returns False if ticket is tampered with and True if ticket is good.

        Arguments:
开发者ID:b3c,项目名称:mod_auth,代码行数:32,代码来源:mod_auth.py


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