Extracted function for getting a private key