It makes no sense to encrypt a file with a private key. Using a private key to attach a tag to a file that guarantees that the file was provided by the holder of the private key is called signing, and the tag is called a signature. There is one popular cryptosystem (textbook RSA) where a simplified (insecure) algorithm uses has public and private keys of the same type,. I have a file server.key generated by openssl genrsa -out server.key 2048, which contains both public and private key. I searched and fount that I can get public key by openssl rsa -in server.key -pubout -out key.pub.
To perform the following actions for Windows or Linux, you must have OpenSSL installed on your system.
Generating the Private Key -- Windows
In Windows:
1. Open the Command Prompt (Start > Programs > Accessories > Command Prompt).
2. Navigate to the following folder:
C:Program FilesListManagertclwebbincerts
3. Type the following:
openssl genrsa -out rsa.private 1024
4. Press ENTER. The private key is generated and saved in a file named 'rsa.private' located in the same folder.
NOTE The number '1024' in the above command indicates the size of the private key. You can choose one of five sizes: 512, 758, 1024, 1536 or 2048 (these numbers represent bits). The larger sizes offer greater security, but this is offset by a penalty in CPU performance. We recommend the best practice size of 1024.