J'ai reçu un fichier PEM avec un certificat et des clés pub/privées. Spécifiquement, il comprend les en-têtesConvertir une clé privée traditionnelle PEM en clé privée PKCS8
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
-----BEGIN RSA PUBLIC KEY-----
-----END RSA PUBLIC KEY-----
dans cet ordre spécifique. Ma compréhension est sans en-tête suivant l'en-tête BEGIN RSA PRIVATE KEY
que ce fichier pem contient une clé privée dans le format traditionnel (PKCS1) sans cryptage.
J'ai besoin de convertir cette clé privée en un format non crypté PKCS8 codé DER pour une utilisation avec le code serveur java, en particulier PKCS8EncodedKeySpec. J'ai essayé OpenSSL, à la fois avec les commandes rsa et pkcs8, mais sans chance. Il n'y a pas de besoin spécifique d'utiliser openssl s'il y a quelque chose de plus simple.
Plus précisément:
openssl rsa -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem
openssl rsa -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem -pubin openssl pkcs8 -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem -nocrypt
J'ai aussi essayé préciser Inform et OutForm sans succès.
[email protected]:~/TestCerts$ openssl rsa -in IServer_Key.pem -out IServer_Key.pkcs8.pem -pubin
unable to load Public Key
5925:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:650:
Expecting: PUBLIC KEY
[email protected]:~/TestCerts$ openssl rsa -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem
unable to load Private Key
5993:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1316:
5993:error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error:tasn_dec.c:828:
5993:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:748:Field=n, Type=RSA
5993:error:0D09A00D:asn1 encoding routines:d2i_PrivateKey:ASN1 lib:d2i_pr.c:99:
5993:error:0907B00D:PEM routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:pem_pkey.c:125:
[email protected]:~/TestCerts$ openssl pkcs8 -in IServer_Key.orig.prikey.pem -out IServer_Key.pkcs8.pem -nocrypt
Error decrypting key
6022:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:650:
Expecting: PRIVATE KEY
Toute aide serait très appréciée à ce stade.
J'ai enlevé la balise java car elle n'est pas du tout limitée à java et j'espère qu'elle obtiendra une audience plus large – cfi
Je pense que la plupart des commandes OpenSSL s'attendent à un seul objet par fichier. Créez un second fichier et ajoutez-y seulement la clé privée (y compris le '----- BEGIN RSA PRIVATE KEY -----' et '----- END RSA PRIVATE KEY -----') . Ensuite, essayez vos commandes. – jww
[Le format par défaut d'Openssl pkcs8 donne RSA PRIVATE KEY] (https://superuser.com/questions/606215/openssl-pkcs8-default-format-gives-rsa-private-key). – jww