An unintended benefit that arose from the invention of public key cryptography was the creation of an ability to digitally sign a document. A digital signature serves the same purpose as a hand written signature but unlike a hand written signature it is nearly impossible to counterfeit. An additional benefit is that a digital signature verifies that there has been no tampering of the document in transit.
To sign a document digitally the public key cryptography system has to be used in the opposite direction to normal. Public key cryptography works by having two keys that complement each other, a public key and a private key. An individual makes their public key freely available to everyone but keeps the private key secret, any data encrypted by the public key can only be decrypted by using the private key. So to securely send a document to someone you would encrypt it using their public key in the knowledge that only they have the private key to be able to read the document.
But interestingly the key system works in reverse so that any document encrypted with an individual's private key can only be decrypted by their public key. This was discarded as an interesting but useless fact about public key cryptography, as anyone can decrypt the document because the public key is freely and widely available. But then upon further inspection it occurred to someone that a document encrypted by an individual using his or her private key can only have been encrypted by that person as no one else has the key. So it as if that document had been digitally signed by the individual that had encrypted it.
Also as the digitally signing process involves the scrambling of the data of the document it is not possible for a third party to alter the contents without causing the document to in effect become unsigned.