Please review the attached patch which addresses the following ticket:

The code was successfully tested on a machine with an attached HSM.