Encryption is done in a similar way as Digital Signature
For more details, please refer to this document. It has detailed descriptions about Encryption and some code segments