def test_pyuecc(self): (pub1, pri1) = pyuecc.make_key() logging.debug('pub key %s' % pub1) logging.debug('pri key %s' % pri1) assert len(pub1) == 64 assert len(pri1) == 64 (pub2, pri2) = pyuecc.make_key() spri1 = pyuecc.shared_secret(pub1, pri2) spri2 = pyuecc.shared_secret(pub2, pri1) logging.debug('shared key %s' % spri1) assert spri1 == spri2 cpub1 = pyuecc.compress(pub1) logging.debug('compressed key %s' % cpub1) assert len(cpub1) == 33 _pub1 = pyuecc.decompress(cpub1) logging.debug('decompressed key %s' % _pub1) assert _pub1 == pub1 msg = b'test' sig1 = pyuecc.sign(pri1, msg) ok = pyuecc.verify(pub1, msg, sig1) logging.debug('signature %s' % sig1) assert ok ok = pyuecc.verify(pub2, msg, sig1) assert not ok
def __init__(self, mynode,): """ init :param MyNode mynode: MyNode instance that represents my key info. """ self.mynode = mynode (self.remote_ephemeral_public, self.remote_ephemeral_private) =\ pyuecc.make_key() self.channel_enckey = None self.channel_deckey = None self.seq = 0 self.token = None
def __init__(self, port, fname=None): """ init :param int port: port number listening from. :param str fname: file name that contains location. is file doesn't exist, keys is saved to this file. """ self.port = port self.ip_address = self.get_ip_address() if fname is not None: my_location = self.get_from_file(fname) if my_location is not None: j = json.loads(my_location) self.public = base64.b64decode(j['public_key']) self.private = base64.b64decode(j['private_key']) return (self.public, self.private) = pyuecc.make_key() if fname is not None: self.save_to_file(fname)