示例#1
0
    def test_key_siwtch(self):
        key = BitcoinVersionedPrivateKey(
            "cN5YgNRq8rbcJwngdp3fRzv833E7Z74TsF8nB6GhzRg8Gd9aGWH1")

        def get_priv_key2(bvpk_private_key):
            return serialization.load_pem_private_key(
                bvpk_private_key.to_pem(),
                password=None,
                backend=default_backend())

        other = get_priv_key(key)
        priv2 = get_priv_key2(key)

        def serialize_priv_key(private_key):
            numbers = private_key.private_numbers()
            return '%x' % numbers.private_value

        ser_priv1 = serialize_priv_key(other)
        ser_priv2 = serialize_priv_key(priv2)
        print "%s\n%s" % (ser_priv1, ser_priv2)

        self.assertEquals(serialize_priv_key(other), serialize_priv_key(priv2))
        self.assertEquals(other.private_numbers(), priv2.private_numbers())

        data = "Hello"
        signature1 = hash_sign_data(other, data)
        signature2 = hash_sign_data(priv2, data)

        self.assertTrue(check_signed_data(other.public_key(), signature2,
                                          data))
        self.assertTrue(check_signed_data(priv2.public_key(), signature1,
                                          data))
示例#2
0
def generate_random_chunk(block_id, key=os.urandom(32), size=1000, min_val=0, max_val=30):
    chunk = ChunkData()
    for i in range(size):
        entry = DoubleEntry(int(time.time()), "test", float(random.uniform(min_val, max_val)))
        chunk.add_entry(entry)

    stream_ident = DataStreamIdentifier(PRIVATE_KEY.public_key().address(), STREAMID, NONCE,
                                        TXID)

    return create_cloud_chunk(stream_ident, block_id, get_priv_key(PRIVATE_KEY), 10, key, chunk)
示例#3
0
 def __init__(self, name, start_time, bc_privatekey,
              policy_nonce, stream_id, txid, ip='127.0.0.1', port=14000):
     self.name = name
     self.start_time = start_time
     self.bc_privatekey = BitcoinVersionedPrivateKey(bc_privatekey)
     self.policy_nonce = base64.b64decode(policy_nonce)
     self.stream_id = stream_id
     self.txid = txid
     self.ip = ip
     self.port = port
     self.local_private_key = get_priv_key(self.bc_privatekey)
示例#4
0
def generate_random_chunk(private_key,
                          block_id,
                          stream_identifier,
                          tag="test",
                          key=os.urandom(32),
                          size=1000,
                          max_float=1000):
    chunk = ChunkData()
    for i in range(size):
        entry = DoubleEntry(int(time.time()), tag,
                            random.uniform(0, max_float))
        chunk.add_entry(entry)
    return create_cloud_chunk(stream_identifier, block_id,
                              get_priv_key(private_key), 0, key, chunk)
示例#5
0
def generate_random_chunk_from_data(chunk,
                                    private_key,
                                    block_id,
                                    stream_identifier,
                                    time_keeper=TimeKeeper(),
                                    do_compression=False):
    time_keeper.start_clock()
    cloud_chunk = create_cloud_chunk(stream_identifier,
                                     block_id,
                                     get_priv_key(private_key),
                                     0,
                                     aes_key,
                                     chunk,
                                     use_compression=do_compression)
    time_keeper.stop_clock("time_create_chunk")
    return cloud_chunk
def generate_cloud_chunk(chunk_data, private_key, block_id, stream_identifier, key=os.urandom(32)):

    return create_cloud_chunk(stream_identifier, block_id, get_priv_key(private_key), 0, key, chunk_data)