I am trying to sign and verify a signature in Solidity. I understood that it is possible to verify a signature using
ecrecover. However, I am not able to find any useful information on signing.
There might be implementations of signing in Solidity, but you shouldn't do it.
This is because in order to sign something, you will need a private key. Since every transaction is public on the blockchain, so will your private key that you use to sign something with.
Therefore, it doesn't make much sense to sign something in Solidity because everyone will be able to see your private key.
I do not agree with @erkt. Really not sure what that even means. Private Keys never go on the blockchain, unless you explicitly put it there. You can refer to some answers already provided here Can someone explain 'signing a transaction' and how its different from sending ether? There are reasons you would sign, but not all transactions need to be signed. Any message you send is implicitly signed and verified by the protocol (miners, verifiers). If you have any specific use case you can sign them before sending and verify using