Skip to Content
Hands-On Blockchain for Python Developers
book

Hands-On Blockchain for Python Developers

by Arjuna Sky Kok
February 2019
Intermediate to advanced
450 pages
9h 59m
English
Packt Publishing
Content preview from Hands-On Blockchain for Python Developers

Multihash

Now, let's hash the serialized data. IPFS uses multihash to hash the data. This means it is not just outputting the hash output, but it also outputs the hash function that it uses, the length of the hash output from that hash function, and the hash output from that hash function.

Let's take a look at an example of the usage of multihash. Suppose the data that we want to hash is b'i love you'. We choose sha256 as a hash function, as follows:

>>> from hashlib import sha256>>> sha256(b'i love you').hexdigest()'1c5863cd55b5a4413fd59f054af57ba3c75c0698b3851d70f99b8de2d5c7338f

Let's check out the length of this hash output:

>>> len('1c5863cd55b5a4413fd59f054af57ba3c75c0698b3851d70f99b8de2d5c7338f')64

Since a number in hexadecimal format ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Blockchain in Action

Blockchain in Action

Bina Ramamurthy
Learn Python by Building a Blockchain and Cryptocurrency

Learn Python by Building a Blockchain and Cryptocurrency

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781788627856Supplemental Content