本文整理汇总了Python中M2Crypto.DSA.pub_key_from_params方法的典型用法代码示例。如果您正苦于以下问题:Python DSA.pub_key_from_params方法的具体用法?Python DSA.pub_key_from_params怎么用?Python DSA.pub_key_from_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类M2Crypto.DSA
的用法示例。
在下文中一共展示了DSA.pub_key_from_params方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dnskey_to_dsa
# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import pub_key_from_params [as 别名]
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)
示例2: test_pub_key_from_params
# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import pub_key_from_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)
示例3: _dnskey_to_dsa
# 需要导入模块: from M2Crypto import DSA [as 别名]
# 或者: from M2Crypto.DSA import pub_key_from_params [as 别名]
def _dnskey_to_dsa(key):
# get T
t, = struct.unpack(b'B',key[0])
offset = 1
# get Q
new_offset = offset+20
q = b''
for c in key[offset:new_offset]:
q += b'%02x' % struct.unpack(b'B',c)[0]
q = bn_to_mpi(hex_to_bn(q))
offset = new_offset
# get P
new_offset = offset+64+(t<<3)
p = b''
for c in key[offset:new_offset]:
p += b'%02x' % struct.unpack(b'B',c)[0]
p = bn_to_mpi(hex_to_bn(p))
offset = new_offset
# get G
new_offset = offset+64+(t<<3)
g = b''
for c in key[offset:new_offset]:
g += b'%02x' % struct.unpack(b'B',c)[0]
g = bn_to_mpi(hex_to_bn(g))
offset = new_offset
# get Y
new_offset = offset+64+(t<<3)
y = b''
for c in key[offset:new_offset]:
y += b'%02x' % struct.unpack(b'B',c)[0]
y = bn_to_mpi(hex_to_bn(y))
offset = new_offset
# create the DSA public key
return DSA.pub_key_from_params(p,q,g,y)