API for signing custom content (token)

Hi,
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:
sign(content)
, 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.

Regards,

Daniel