In RHEL systems and derivatives, you can use openssl
for this task:
# openssl pkcs8 --help
Usage pkcs8 [options]
where options are
-in file input file
-inform X input format (DER or PEM)
-passin arg input file pass phrase source
-outform X output format (DER or PEM)
-out file output file
-passout arg output file pass phrase source
-topk8 output PKCS8 file
-nooct use (nonstandard) no octet format
-embed use (nonstandard) embedded DSA parameters format
-nsdb use (nonstandard) DSA Netscape DB format
-noiter use 1 as iteration count
-nocrypt use or expect unencrypted private key
-v2 alg use PKCS#5 v2.0 and cipher "alg"
-v1 obj use PKCS#5 v1.5 and cipher "alg"
-engine e use engine e, possibly a hardware device.
Moreover, the pkcs8(1)
manpage provides several examples.
openssl pkcs8 -topk8 -in private.key.pem -out private.key.pk8.pem -v2 des3
This Q/A in the SEC.SE site provides a very detailed description of this process and the cryptography involved.