-
-
Notifications
You must be signed in to change notification settings - Fork 6
Generate public and private key
Here is a small description how to generate the public and private key with OpenSSL.
:~$ openssl genrsa -out keypair.pem 2048
Generating RSA private key, 2048 bit long modulus
.................................................
.................................................
....................+++
e is 65537 (0x10001)
The above command creates the 'keypair.pem' file in the current directory.
To convert it into the required (PKCS#8, DER) format:
:~$ openssl pkcs8 -topk8 -in keypair.pem -outform DER -out private.der -nocrypt
writing RSA key
This creates the file 'private.der' what represents the private key in der format.
The next step is to generate the pendant public key from the private key:
:~$ openssl rsa -in keypair.pem -outform DER -pubout -out public.der
This creates the file 'public.der' what represents the public key in der format.
The generated files are used in the project mystic-core in the unit tests.
To generate from the above private key file a public key file in pem format you have to run this command:
:~$ openssl rsa -pubout -in keypair.pem -out public.pem
This creates the file 'public.pem' what represents the public key in pem format.
Of course you can generate the public and private key with java as shown in the following snippet:
import de.alpharogroup.crypto.algorithm.KeyPairGeneratorAlgorithm;
import de.alpharogroup.crypto.factories.KeyPairFactory;
...
KeyPair keyPair = KeyPairFactory.newKeyPair(KeyPairGeneratorAlgorithm.RSA, 2048);
PrivateKey privateKey = keyPair.getPrivate();
PublicKey publicKey = keyPair.getPublic();
- keystore-explorer KeyStore Explorer is a free GUI replacement for the Java command-line utilities keytool and jarsigner.