This question already has an answer here:

How can I use the private key of my eth.accounts[0] to sign a file from outside Ethereum, so people can verify that the file belongs to that account with the public key?

marked as duplicate by Tjaden Hess, Chenmunka, kenorb, Dawny33, Waqar Lim Jan 29 '16 at 16:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.