My servlet generates pair of keys(public and private) when the client makes a request for keys and sends the public key to the client using ObjectOutputStream, which is working fine.
The client then encrypts data using the public key and sends it the servlet again.
so again the servlets executes from the beginning and a new set of keys are generated which I don’t want.
I want to be able to use the old private key to decrypt the message?
what should i do?
Create the keys only once when the servlet itself is created, not on every request. You can create the public and private key pair in the servlet’s
initmethod and then store it in an instance variable of the servlet.There is a nice description here.