Generate public and private key practices:
Generating a private key, here for elliptic curve secp256k1 Example:
-name secp256k1 -genkey -out ecparam OpenSSL secp256k1-priv.pem # EC with curve parameters
OpenSSL ecparam -name secp256k1 -genkey secp256k1 -noout -out-priv.pem # curve parameters without EC
View the contents of the private key file, including hex encoded form of private and public keys:
openssl pkey -in secp256k1-priv.pem -text
The public key corresponding to the secret key generation:
openssl ec -in secp256k1-priv.key -pubout -out secp256k1-pub.key
There are generally two private key file formats pkcs # 1 and pkcs # 8, the default is generated above pkcs # 1 format,
pkcs # 1 includes the head and tail format:
-----BEGIN EC PRIVATE KEY-----
......
-----END EC PRIVATE KEY-----
pkcs # 8 includes the head and tail format
-----BEGIN PRIVATE KEY-----
......
-----END PRIVATE KEY-----
If you want to convert pkcs # 8 format:
openssl pkcs8 -topk8 -nocrypt -in secp256k1-priv.key -out secp256k1-priv-pk8.key