def main(): """Main.""" test = Transaction(123, "Dane", "Someone else", "memes", "memez") print(test.sign_transaction) text = b"Meow Meow Meow" sign.verify(text, sign.sign(text)) print("Unix Epoch: " + str(time.time())) data1 = ["314", "123", "987", "000", "555"] # 0x20000f00 difficulty = int(hex(0x000f00 * int((math.pow(2, 8 * (0x20 - 3))))), 16) chain1 = Chain() block1 = Block(1, 2, "Richard Nixon :P", difficulty, time.time(), chain1.blocks[-1], data1) block1.mine() chain1.add_block(block1) chain1.write() print("Header:\n" + block1.header) print("Data:\n" + str(block1.data)) Transactions = [] for i in range(64): Transactions.append( Transaction("token1", "John" + str(i), "John" + str(i + 1), "Block Talk", "Blah Blah Blah " + str(i)).transaction) block2 = Block(1, 2, "Al Gore :P", difficulty, time.time(), chain1.blocks[-1], Transactions) block2.mine()
def test_verify(): key = RSA.importKey(PUBLIC_KEY) tmp_dir = tempfile.mkdtemp() data_path = join(tmp_dir, 'data') write_message(data_path) assert sign.verify(data_path, key, SIGNATURE) shutil.rmtree(tmp_dir)
def sign_transaction(self): """Sign Transaction.""" signature = sign(self.transaction.encode("utf-8")) if sign.verify(self.transaction.encode("utf-8"), signature): print("Transaction Signed Successfully!") return signature else: print("Transaction could not be signed.") return None
def test_roundabout(): tmp_dir = tempfile.mkdtemp() key_path = join(tmp_dir, 'key') data_path = join(tmp_dir, 'data') write_message(data_path) sign.keygen(key_path) key = RSA.importKey(open('%s.priv' % key_path).read()) sig = sign.sign(data_path, key) assert sign.verify(data_path, key, sig) shutil.rmtree(tmp_dir)
def test_randomdata(): key = RSA.importKey(PRIVATE_KEY) tmp_dir = tempfile.mkdtemp() data_path = join(tmp_dir, 'data') for x in range(100): with open(data_path, 'wb') as fo: fo.write(Random.new().read(100)) assert sign.verify(data_path, key, sign.sign(data_path, key)) shutil.rmtree(tmp_dir)
def getnewsha1(self,path,oldsha1): output = FileUtil.open(path,"wb") output.write(self.netopen('/'+common.CONFIG_SHA1)) output.close() input = FileUtil.open(path,"r") tmp2 = input.read() input.close() hash = self.netopen('/'+common.CONFIG_SIGN) print 'Verifing Hash Table.....' ok = verify(tmp2,hash) if not ok: print 'Verify Failed!' sys.exit() print 'Verify Successful1!'
def getnewsha1(self, path, oldsha1): output = FileUtil.open(path, "wb") output.write(self.getfile('/' + common.CONFIG_SHA1)) output.close() input = FileUtil.open(path, "r") tmp2 = input.read() input.close() hash = self.getfile('/' + common.CONFIG_SIGN) print 'Verifing Hash Table.....' ok = verify(tmp2, hash) if not ok: print 'Verify Failed!' raise urllib2.HTTPError(filename, '500', 'Verify Failed!', '', None) print 'Verify Successful1!'
def chain_verify(input_data): data = input_data.split('$') paired_data = tuple(zip(data[::2], data[1::2])) value, serial_no = paired_data[0] for i in range(1, len(paired_data)): sub_data = data[:i * 2 + 2] msg = '$'.join(sub_data[:-1]) prev_owner_pubk = sub_data[-2] if i == 1: pubk = gold_pubkh else: pubk = prev_owner_pubk signature = sub_data[-1] if not verify(ADDRESS_DICT[pubk], msg, signature): return False return True
def verify(self, key, msg, sign): return s.verify(msg, sign, s.importKey(key), self.__hash_alg)