There is a REST API service. An endpoint is responsible for creation of user accounts. Each user is supposed to have an RSA keypair generated and stored on a server. To protect the private keys from being read by a possible adversary, private keys are encoded to PEM. PEM format is encrypted with AES-256-CBC using a passphrase. The passphrase is same as the one a user is using to log in.
So far I have been generating a keypair within a request handler. But that in some cases takes 10 seconds which is undesirable.
What would be a safe, performance-wise solution to this problem? I want to avoid storing a passphrase in plain-text for later encryption.