I'm about to use thales hsm just for doing some aes encryption/decryption with using http://www.pkcs11interop.net/
But, I have one question raised in my mind. I have two ways to use thales hsm with my server application
One way is that: whenever i need to do aes operation, open a connection, do the job, close the connection.
The other way: open the connection at the start of the server application, do aes operations in the lifetime of the server application, close the connection whenever the server needs to be closed.
So my question is, which way is the correct (or suggested) way of using hsm?