What I want to do is to digitally sign a document. I am new to cryptography and was wondering what issues to take into account. The only criteria is that a textual document signed should produce a code that is different if lines in the same document are shifted. I heard that MD5 is broken and that one should avoid SHA1 (because of NSA etc).

As I said, I am new to crypto. Any suggestions would be welcome!

  • 2
    $\begingroup$ You should clarify whether or not you want to compute a hash or digitally sign it. The last sentence makes me wonder if you understand the difference. In general, just compute an RSA signature using a strong hash (SHA2 or SHA3 if paranoid about the NSA). $\endgroup$ Commented Jun 18, 2014 at 10:48
  • $\begingroup$ Who is the recipient of the signed document? How do you do key exchange? In other words, typically to sign a document you need a public/private key pair and the recipient of the document must have some way of knowing that the public key belongs to you and not someone pretending to be you. How is the document sent to the recipient (e.g., email)? $\endgroup$
    – mikeazo
    Commented Jun 18, 2014 at 11:27
  • $\begingroup$ The document is public, only me who has the "authority" to give out this document. In other documents, somebody reading the document should trust it is coming from me. No key exchange, I just want to put a text in a document saying it has been signed. Does it make sense? $\endgroup$ Commented Jun 18, 2014 at 12:04
  • 2
    $\begingroup$ How do you intend for anyone to verify that it has been signed and, if so, by you? $\endgroup$ Commented Jun 18, 2014 at 12:07
  • $\begingroup$ Edvard, thats a good question. I guess they would need to go to my website, find the document and check whether the signed code is the same as the document they want to check. $\endgroup$ Commented Jun 18, 2014 at 14:13

2 Answers 2


I guess they would need to go to my website, find the document and check whether the signed code is the same as the document they want to check.

If you assume people are able to trust your website, you could simply list the SHA-256 (for example) hashes of your documents on your website. Perhaps include an URL in the signed document pointing to a particular page on your site that lists the hash for that file.

Trusting others to get the correct hash from your website when they visit the URL would remain unsolved. Someone could intercept the request and return a different hash that matches a modified document they've distributed.

The more complex option is public key signatures.

If you go that way you would use something like GPG/PGP to generate a key-pair, distribute the public key, then sign the documents using the private key. In this case an attacker couldn't produce a different signature that matches your key even if they controlled requests to the documents and your website.

However, you would still need to get your public key into the hands of anyone wanting to verify the signature. An attacker who could distribute their own key as yours could again forge signed documents in your name.


First thing Hashing and digitally signing are different things.


A hash function is any function that can be used to map data of arbitrary size to data of fixed size, with slight differences in input data producing very big differences in output data.

Digital Signatures

A digital signature is a mathematical scheme for demonstrating the authenticity of a digital message or document. A valid digital signature gives a recipient reason to believe that the message was created by a known sender, such that the sender cannot deny having sent the message (authentication and non-repudiation) and that the message was not altered in transit (integrity).

To digitally sign a document you can use a public key encryption scheme. This works by having a personal private public key pair. By making the public key available publicly and keeping your private key. You can use your private key to encrypt the message. This message can only be decrypted by your public key! Because only you have access to the private key, others can be sure that you are the sender if your message is decrypted successfully by your public key! RSA is a widely used encryption algorithm in this scheme. I hope this helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.