本文整理汇总了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)
示例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
示例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
示例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)))
示例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)
示例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)
示例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'
示例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: