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


Python PublicKey.ElGamal类代码示例

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


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

示例1: ElGamalKey

def ElGamalKey(pub=None, priv=None, fd=None):
    """
    make ElGamal KeyPair Object
    """
    if fd is not None:
        pub = int.from_bytes(fd.read(256), 'big')
        priv = int.from_bytes(fd.read(256), 'big')
    if priv:
        return ElGamal.construct((elgamal_p, elgamal_g, pub, priv))
    return ElGamal.construct((elgamal_p, elgamal_g, pub))
开发者ID:rfree,项目名称:python-i2cp,代码行数:10,代码来源:crypto.py

示例2: test_encryption

 def test_encryption(self):
     for tv in self.tve:
         d = self.convert_tv(tv, True)
         key = ElGamal.construct(d['key'])
         ct = key._encrypt(d['pt'], d['k'])
         self.assertEquals(ct[0], d['ct1'])
         self.assertEquals(ct[1], d['ct2'])
开发者ID:Gnof,项目名称:pycryptodome,代码行数:7,代码来源:test_ElGamal.py

示例3: test_decryption

 def test_decryption(self):
     for tv in self.tve:
         for as_longs in (0, 1):
             d = self.convert_tv(tv, as_longs)
             key = ElGamal.construct(d["key"])
             pt = key.decrypt((d["ct1"], d["ct2"]))
             self.assertEqual(pt, d["pt"])
开发者ID:rashbhat,项目名称:BankApplication,代码行数:7,代码来源:test_ElGamal.py

示例4: test_signing

 def test_signing(self):
     for tv in self.tvs:
         d = self.convert_tv(tv, True)
         key = ElGamal.construct(d['key'])
         sig1, sig2 = key._sign(d['h'], d['k'])
         self.assertEquals(sig1, d['sig1'])
         self.assertEquals(sig2, d['sig2'])
开发者ID:Gnof,项目名称:pycryptodome,代码行数:7,代码来源:test_ElGamal.py

示例5: sign_ElGamal

def sign_ElGamal(msg, key_tuple, k=None):
    """Create an ElGamal signature.

    :Parameters:
        - `msg`: string of data signature applies to 
        - `key_tuple`: tuple ElGamal key integers (p, g, x)
          (see `ElGamal key tuple`_)
        - `k`: integer (must be relatively prime to p-1)

    :Returns: tuple (integer, integer) ElGamal signature values (a, b)
    
    .. _ElGamal key tuple:

    ElGamal key tuple:
            
        - `p`: integer ElGamal prime
        - `g`: integer ElGamal random "g" value
        - `x`: integer ElGamal private key
    """
    import Crypto.PublicKey.ElGamal as ELG
    if k is None: # generate our own prime k value (k relatively prime to p-1)
        import Crypto.Util.number as NUM
        import Crypto.Util.randpool as RND
        rnd = RND.RandomPool()
        q = key_tuple[0] # no restrictions on bit length for k, good enough?
        k = NUM.getPrime(8*len(STN.int2str(q)), rnd.get_bytes)
    elg = ELG.construct((key_tuple[0], key_tuple[1], 0, key_tuple[2]))
    return elg.sign(msg, k)
开发者ID:Ando02,项目名称:wubiuefi,代码行数:28,代码来源:crypto.py

示例6: verify_ElGamal

def verify_ElGamal(msg, sig_tuple, key_tuple):
    """Verify an ElGamal signature.

    :Parameters:
        - `msg`: string of data signature applies to 
        - `sig_tuple`: tuple of ElGamal signature integers (a, b)
          (see `ElGamal signature tuple`_)
        - `key_tuple`: tuple of ElGamal key integers (p, g, y)
          (see `ElGamal key tuple`_)

    :Returns: tuple (integer, None) where integer == 1 or 0, verification
        true or false
    
    .. _ElGamal signature tuple:

    ElGamal signature tuple:
            
        - `a`: integer ElGamal "a"
        - `b`: integer ElGamal "b"
            
    .. _ElGamal key tuple:

    ElGamal key tuple:
            
        - `p`: integer ElGamal prime
        - `g`: integer ElGamal group
        - `y`: integer ElGamal public key
    """
    import Crypto.PublicKey.ElGamal as ELG
    elg = ELG.construct(key_tuple) # note change in ordering
    return elg.verify(msg, sig_tuple)
开发者ID:Ando02,项目名称:wubiuefi,代码行数:31,代码来源:crypto.py

示例7: load_unencrypted

	def load_unencrypted(pkeyInfo):
		version, pkeyAlgo, pkeyData = pkeyInfo[0:3]
		if version != 0:
			raise PKCSError('unknown PKCS#8 version: {}'.format(version))
		algoId, algoParms = pkeyAlgo.get_pos(0,2)
		if algoId == OID_PKCS_RSAPKEY:
			from Crypto.PublicKey import RSA
			rsakey = asn1.loads(pkeyData)
			vals = rsakey[1:6] # n, e, d, p, q
			pkey = RSA.construct([long(val) for val in vals])
			print 'RSA!', vals
		elif algoId == OID_PKCS_DSAPKEY:
			from Crypto.PublicKey import DSA
			p, q, g = algoParms
			x = asn1.loads(pkeyData)
			y = pow(g, x, p)
			vals = (y, g, p, q, x)
			pkey = DSA.construct([long(val) for val in vals])
		elif algoId == OID_PKCS_DHPKEY:
			from Crypto.PublicKey import ElGamal
			p, g = algoParms[0:2]
			x = asn1.loads(pkeyData)
			y = pow(g, x, p)
			vals = (p, g, y, x)
			pkey = ElGamal.construct([long(val) for val in vals])
		else:
			raise PKCSError('unknown PKCS#8 key algorithm: {}'.format(algoId))
		return pkey
开发者ID:tlhquynh,项目名称:python-asn1,代码行数:28,代码来源:pkcs.py

示例8: test_decryption

 def test_decryption(self):
     for tv in self.tve:
         for as_longs in (0,1):
             d = self.convert_tv(tv, as_longs)
             key = ElGamal.construct(d['key'])
             pt = key.decrypt((d['ct1'], d['ct2']))
             self.assertEquals(pt, d['pt'])
开发者ID:amos402,项目名称:Arianrhod,代码行数:7,代码来源:test_ElGamal.py

示例9: _test_random_key

 def _test_random_key(self, bits):
     elgObj = ElGamal.generate(bits, Random.new().read)
     self._check_private_key(elgObj)
     self._exercise_primitive(elgObj)
     pub = elgObj.publickey()
     self._check_public_key(pub)
     self._exercise_public_primitive(elgObj)
开发者ID:amos402,项目名称:Arianrhod,代码行数:7,代码来源:test_ElGamal.py

示例10: reencrypt

    def reencrypt(self, cipher, pubkey=None):
        '''
        >>> B = 64
        >>> k = AVCrypt(bits=B)
        >>> clears = [random.StrongRandom().randint(1, B) for i in range(5)]
        >>> cipher = [k.encrypt(i) for i in clears]
        >>> cipher2 = [k.reencrypt(i) for i in cipher]
        >>> d = [k.decrypt(i) for i in cipher]
        >>> d2 = [k.decrypt(i) for i in cipher2]
        >>> clears == d == d2
        True
        >>> cipher != cipher2
        True
        '''

        if pubkey:
            p, g, y = pubkey
            k = ElGamal.construct((p, g, y))
        else:
            k = self.k

        a, b = cipher
        a1, b1 = self.encrypt(1, k=k)

        return ((a * a1) % k.p, (b * b1) % k.p)
开发者ID:danigm,项目名称:avmixnet,代码行数:25,代码来源:avcrypt.py

示例11: test_encryption

 def test_encryption(self):
     for tv in self.tve:
         for as_longs in (0, 1):
             d = self.convert_tv(tv, as_longs)
             key = ElGamal.construct(d["key"])
             ct = key.encrypt(d["pt"], d["k"])
             self.assertEqual(ct[0], d["ct1"])
             self.assertEqual(ct[1], d["ct2"])
开发者ID:rashbhat,项目名称:BankApplication,代码行数:8,代码来源:test_ElGamal.py

示例12: get_key

def get_key():
	key = ElGamal.generate(256, get_random_bytes)
	comps = ('p','g','y','x')
	out = '\n'.join(["{} = {}".format(comp,getattr(key, comp)) for comp in comps])
	with open('./key', 'w+') as k:
		k.write(out)
	key.set_key(user, out['y'],out['x'])
	return key
开发者ID:Shodhanth,项目名称:SecureSync,代码行数:8,代码来源:keygen.py

示例13: test_encryption

 def test_encryption(self):
     for tv in self.tve:
         for as_longs in (0,1):
             d = self.convert_tv(tv, as_longs)
             key = ElGamal.construct(d['key'])
             ct = key.encrypt(d['pt'], d['k'])
             self.assertEquals(ct[0], d['ct1'])
             self.assertEquals(ct[1], d['ct2'])
开发者ID:amos402,项目名称:Arianrhod,代码行数:8,代码来源:test_ElGamal.py

示例14: test_signing

 def test_signing(self):
     for tv in self.tvs:
         for as_longs in (0, 1):
             d = self.convert_tv(tv, as_longs)
             key = ElGamal.construct(d["key"])
             sig1, sig2 = key.sign(d["h"], d["k"])
             self.assertEqual(sig1, d["sig1"])
             self.assertEqual(sig2, d["sig2"])
开发者ID:rashbhat,项目名称:BankApplication,代码行数:8,代码来源:test_ElGamal.py

示例15: test_signing

 def test_signing(self):
     for tv in self.tvs:
         for as_longs in (0,1):
             d = self.convert_tv(tv, as_longs)
             key = ElGamal.construct(d['key'])
             sig1, sig2 = key.sign(d['h'], d['k'])
             self.assertEquals(sig1, d['sig1'])
             self.assertEquals(sig2, d['sig2'])
开发者ID:amos402,项目名称:Arianrhod,代码行数:8,代码来源:test_ElGamal.py


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