def test():
    """Test cases """
    from Crypto.PublicKey import RSA

    keyAlice = PublicKey(RSA.generate(2048).publickey())
    keyBob = PublicKey(RSA.generate(2048).publickey())

    pbkm = PublicKeyMap()
    pbkm.addKey("Alice", keyAlice)
    pbkm.addKey("Bob", keyBob)
    print("After adding keys for Alice and Bob")
    print(pbkm)
    print("public key for Alice = ", pbkm.getPublicKey("Alice"))
    print("keyname for keyAlice = ", pbkm.getKeyName(keyAlice))
    print("Keynames = ", pbkm.getKeyNames())
    print("PublicKeyMap=\n", pbkm)
Beispiel #2
0
    def __init__(self, cryptosystem, private_key_value):
        """
        Creates a new private key. Should not be invoked directly.
        
        Instead of using this constructor from outside of PloneVoteCryptoLib, 
        please use the class methods EGCryptoSystem.new_key_pair() or 
        PrivateKey.from_file(file).
        
        Arguments:
            cryptosystem::EGCryptoSystem-- The ElGamal cryptosystem in which 
                                           this key is defined.
            private_key_value::long     -- The actual value of the private key.
        """
        public_key_value = pow(cryptosystem.get_generator(), private_key_value,
                               cryptosystem.get_prime())

        self.cryptosystem = cryptosystem
        self.public_key = PublicKey(cryptosystem, public_key_value)
        self._key = private_key_value
 def toPublicKey(self):
     return PublicKey(self.privateKey.publickey())