Generate pem pkcs8 with key rsa nodejs - node.js

I have a .key file with password and I need to get the .pem file with RSA PKCS8 method with NodeJS function.
The command I use to do it with OpenSSL is the following
openssl pkcs8 -inform DER -in file.key -out file.pem -passin pass:passwordkey

Related

How to convert an SSL certificate in linux

Is there a way how to convert certificates between cer/pem/crt/der/pfx/p12 in Linux? I have an SSL certificate in a .cer file and I need it to be .pem in order to use it.
How can I convert it?
Converting certificates between cer/pem/crt/der/pfx/p12 can be done in Linux with the use of OpenSSL tool via the terminal.
These commands allow you to convert certificates and keys to different formats to make them compatible with specific types of servers or software.
Convert a DER file (.crt .cer .der) to PEM
openssl x509 -inform der -in certificate.cer -out certificate.pem
Convert a PEM file to DER
openssl x509 -outform der -in certificate.pem -out certificate.der
Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM
openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes
You can add -nocerts to only output the private key or add -nokeys to only output the certificates.
Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt
For more information see:
http://www.sslshopper.com/article-most-common-openssl-commands.html
https://support.ssl.com/index.php?/Knowledgebase/Article/View/19
Convert .crt to .p12
openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt
Where server.key , is the server key .
server.crt is cert file from CA or self sigh

openssl set password for private key in command line

I'm trying to encrypt some data via openssl tool, and the question is how can I set password for private.key in this command:
openssl smime -sign -signer /var/www/protected/keys/ym.pem -inkey /var/www/protected/keys/ym.key -nochain -nocerts -outform PEM -nodetach
For those who faces with the same problem:
Remove a passphrase from a private key this way:
openssl rsa -in privateKey.pem -out newPrivateKey.pem

Encrypt and decrypt a string of text with RSA and DES3 key

I am using the Linux command line, I have created a Private Key using the following command:
openssl genrsa -des3 -out private.pem 2048
I have extracted the public key from the private key like so:
openssl rsa -in private.pem -out public.pem -outform PEM -pubout
I want to use the public key to encrypt a string of text, lets say "foo bar", and then decrypt this string again.
How do I go about this?
Thanks
I think you want
openssl rsautl -encrypt -inkey public.pem -pubin -in unencrypted_file.txt -out encrypted_file.ssl
See more at devco.

How to encrypt an XML file in Ubuntu with openssl using the public key?

can any one able to tell me how to encrypt and decrypt an xml file using openssl.
i can able to create privatekey using the linux command
openssl genrsa -out private.pem 1024 and got my private key as private.pem
also i create public key using
openssl rsa -in private.pem -out public.pem -outform PEM -pubout got my public key as public.pem
now wat i want is i want to encrypt the xml file using this public key and again want to decrypt using my private key....please help me...
thanks in advance
I think what you are looking for is this:
If you have a PEM encoded key:
openssl pkeyutl -encrypt -in FileToEncrypt -out EncryptedData.enc -inkey ThePathToYourPublicKey -keyform PEM
If you have a DER encoded key:
openssl pkeyutl -encrypt -in FileToEncrypt -out EncryptedData.enc -inkey ThePathToYourPublicKey -keyform DER
You then decrypt with:
openssl pkeyutl -decrypt -in EncryptedData.enc -out DecryptedFile -inkey ThePathToYourPrivateKey
For more information about this you can consult openssl's pkeyutil documentation.
If you want to use S/MIME packaging (a standard used to encrypt/decrypt/sign e-mails), see openssl's smime documentation.
Encrypt with public key:
openssl rsautl -encrypt -inkey public.pem -pubin -in xml.file -out encrypted.enc
Decrypt with private key:
openssl rsautl -decrypt -inkey private.pem -in encrypted.enc -out xml.txt

How to encrypt and decrypt xml using openSSL with public key

Can any one able to tell me how to encrypt and decrypt a xml file using openssl. I can able to create privatekey using the Linux command
openssl genrsa -out private.pem 1024
And got my private key as private.pem. Created public key using
openssl rsa -in private.pem -out public.pem -outform PEM -pubout
got my public key as public.pem
Now what I want is I want to encrypt the XML file using this public key and again want to decrypt using my private key.
Try:
$ openssl rsautl -encrypt -inkey public.pem -pubin -in file.xml -out file.xml.encrypted
Hint: I cheated and looked here:
http://www.devco.net/archives/2006/02/13/public_-_private_key_encryption_using_openssl.php

Resources