Blockchain for documents
Blockchain for documents
Premium licenses include a set of features intended to work with documents in blockchains.
This way, it is possible to generate unique digests per document, as a whole or just a part of it depending on its content, and storage them in the blockchain. This allows for verifying and guaranteeing the content of documents, and ensures that they don't have undergone any unauthorized changes. The blockchain feature also allows for creating changelogs of versions according to digests, associating documents to users and many other possibilities.
phpdocx Premium enables the work with public and private blockchains based on Ethereum. In case of wanting to use other blockchain type, the features available on phpdocx are anyway quite handy to create unique digests per document in order to confirm its content.
Ethereum has become the most popular blockchain. Among its numerous benefits, the smart contracts and its own programming language are the ones that stand out.
Besides the Ethereum public network, thanks to the availability of its code, it is viable to create private networks of nodes to implement a closed blockchain. phpdocx Premium accepts both types of networks, public and private, to work with documents.
To create a private Ethereum network, the simplest procedure is to install geth (https://github.com/ethereum/go-ethereum/wiki/geth), an application meant to execute ethereum nodes.
The class Blockchain.php, available in phpdocx Premium licenses, makes possible the generation of digests in SHA256 of DOCX and PDF documents. It is very easy to use. Just create an instance of the class
Then execute the following code for DOCX documents:
Or this one for PDF documents:
Both methods return an alphanumeric string, coded with SHA256, which unequivocally identifies the content of the file. This string is the one that has to be saved on the blockchain in order to ensure its content.
Ethereum smart contracts enable the storage of contents on blockchains. phpdocx includes some smart contracts as an example, which are ready to customize or employ as a basis to create new ones.
What follows is a simple smart contract to store information:
After compiling this smart contract
two new files are generated on the target directory:
The next code stores the digest with web3:
The previous code generates an address after saving the information. This address is necessary to recover the stored digest.
E.g., if one has obtained the address 0xa2a43d3da953ea8cef568b7f1e3aac3efbfde80b using the previous code, the following code
returns the digest value: bpUpRiJfHrKmpl83lIdE6/VP55pzQc/xHIM4p+WnkK0=
Besides the methods to generate digests above mentioned, the phpdocx Blockchain class offer some other ones:
- insertAddress: adds the address information obtained from Ethereum (or any other blockchain) as a custom property. This method stores the address in the very same document instead of a data base or external medium, making possible to compare the document digest with the one stored on the blockchain, in order to confirm its content.
- getAddress: recovers the custom property value stored with the method insertAddress.