API for signing custom content (token)

We were wondering if there is an API interface to sign any custom content. I.e. we are looking for an interface for an authenticated user:
, where content can be any JSON. As a result we would like to have either just the signature (generated from the private key of the user), or an envelope with content + signature. Is there something like this? Could I use an existing interface for a similar functionality?
Thanks for any help.