# The “openssl genrsa” command only generates a private key?

The command :

openssl genrsa -out RootCA.key 4096


generates a single file named RootCA.key. When I open the file, it only contains the private key.

Then the next command:

openssl req -new -x509 -days 1000 -key RootCA.key -out RootCA.crt


Generates a certificate , named RootCA.crt containing the Root's public key.

How can the second command generate a public key, given ONLY the private key?
Isn't the whole value of cryptography depends on the impossibility of generating one key from another in a key pair ??

How can the second command generate a public key, given ONLY the private key?

It will probably use the public key encoded in the private key datastructure. As per RFC 3447 / PKCS1 (v2.1) the RSAPrivateKey should contain:

RSAPrivateKey ::= SEQUENCE {
version           Version,
modulus           INTEGER,  -- n
publicExponent    INTEGER,  -- e
privateExponent   INTEGER,  -- d
prime1            INTEGER,  -- p
prime2            INTEGER,  -- q
exponent1         INTEGER,  -- d mod (p-1)
exponent2         INTEGER,  -- d mod (q-1)
coefficient       INTEGER,  -- (inverse of q) mod p
otherPrimeInfos   OtherPrimeInfos OPTIONAL
}


which contains a public key $(n,e)$ as well as the private key $(n,d)$ and some other useful information.

Isn't the whole value of cryptography depends on the impossibility of generating one key from another in a key pair?

No. Generating the public key from the private key is fine. Generating the private key from the public key is not. And in fact with RSA, it can be hard to recover the public key from the private key, if you only store the private exponent $d$ and the public modulus $n$ (which is the bare minimum needed for private-key operations) and if you pick the public exponent $e$ not to be the standard $65537=2^{16}+1$ but some random large integer.

On the other hand, for DSA and ECDSA, the private key is only an integer $d$ and the public key is $g^d$ for some fixed $g$ which is needed for private key operations. So recovering the public key from the private key is always and inevitably possible with (EC)DSA.