Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Convert PFX Windows Cert to Linux Public/Private Key and Chain
- openssl pkcs12 -in ./cert.pfx -clcerts -nokeys -out public.crt
- openssl pkcs12 -in ./cert.pfx -nocerts -nodes -out private.rsa
- cat public.crt ca-bundle.crt >> bundle.crt
- openssl pkcs12 -in file.pfx -nocerts -out privateKey.pem
- openssl pkcs12 -in file.pfx -clcerts -nokeys -out publicCert.cer
- openssl rsa -in privateKey.pem -out privateKey_nopasswd.pem
- openssl pkcs12 -in file.pfx -nocerts -out file.pem -nodes
- openssl pkcs12 -in file.pfx -clcerts -nokeys -out file.cert
- #Creating the certs from pfx
- openssl pkcs12 -nocerts -in ssl.pfx -out ssl.key -nodes
- openssl pkcs12 -nokeys -clcerts -in ssl.pfx -out ssl.cer -nodes
- openssl pkcs12 -nokeys -cacerts -in ssl.pfx -out ssl.crt -nodes
- #Checking the certs
- openssl x509 -noout -modulus -in ssl.cer | openssl md5
- openssl rsa -noout -modulus -in ssl.key | openssl md5
- #To read a certificate file:
- openssl x509 -inform PEM -in servercert.pem -text
- #To read a private key file:
- openssl rsa -noout -text -in serverkey.pem
- #To read a CSR request:
- openssl req -noout -text -in serverreq.pem
- #To view CER/DER (binary) files:
- openssl x509 -noout -text -in exported.crt -inform DER
- #To read a CRL PEM file
- openssl crl -inform PEM -in crl.pem -text
- #To convert pem files to pfx files:
- openssl pkcs12 -export -in clientcert.pem -inkey clientkey.pem -out bbva_cert.pfx
- #To convert pfx files to pem files:
- openssl pkcs12 -nocerts -in "trader certificate.pfx" -out clientkey.pem #(outputs the key)
- openssl pkcs12 -clcerts -nokeys -in "trader certificate.pfx" -out clientcert.pem #(outputs the cert)
- openssl rsa -in key.pem -out newkey.pem #remove the pem passphrase
- #To convert CER/DER (binary) files to the .PEM format used by the SCS:
- openssl x509 -inform DER -in cert.cer -out rootcacert.pem
- #To convert CRL DER files into CRL for PEM
- openssl crl -inform DER -in site_name.crt -outform PEM -out site_name.pem
- #To make a test SSL connection and download the server certificate
- openssl s_client -connect remote.host:443
- #To make a test SSL connection using a client certificate
- openssl s_client -cert clientcert.pem -key clientkey.pem -connect remote.host:443
- General OpenSSL Commands
- These commands allow you to generate CSRs, Certificates, Private Keys and do other miscellaneous tasks.
- Generate a new private key and Certificate Signing Request
- openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key
- Generate a self-signed certificate (see How to Create and Install an Apache Self Signed Certificate for more info)
- openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt
- Generate a certificate signing request (CSR) for an existing private key
- openssl req -out CSR.csr -key privateKey.key -new
- Generate a certificate signing request based on an existing certificate
- openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key
- Remove a passphrase from a private key
- openssl rsa -in privateKey.pem -out newPrivateKey.pem
- Checking Using OpenSSL
- If you need to check the information within a Certificate, CSR or Private Key, use these commands. You can also check CSRs and check certificates using our online tools.
- Check a Certificate Signing Request (CSR)
- openssl req -text -noout -verify -in CSR.csr
- Check a private key
- openssl rsa -in privateKey.key -check
- Check a certificate
- openssl x509 -in certificate.crt -text -noout
- Check a PKCS#12 file (.pfx or .p12)
- openssl pkcs12 -info -in keyStore.p12
- Debugging Using OpenSSL
- If you are receiving an error that the private doesn't match the certificate or that a certificate that you installed to a site is not trusted, try one of these commands. If you are trying to verify that an SSL certificate is installed correctly, be sure to check out the SSL Checker.
- Check an MD5 hash of the public key to ensure that it matches with what is in a CSR or private key
- openssl x509 -noout -modulus -in certificate.crt | openssl md5
- openssl rsa -noout -modulus -in privateKey.key | openssl md5
- openssl req -noout -modulus -in CSR.csr | openssl md5
- Check an SSL connection. All the certificates (including Intermediates) should be displayed
- openssl s_client -connect www.paypal.com:443
- Converting Using OpenSSL
- These commands allow you to convert certificates and keys to different formats to make them compatible with specific types of servers or software. For example, you can convert a normal PEM file that would work with Apache to a PFX (PKCS#12) file and use it with Tomcat or IIS. Use our SSL Converter to convert certificates without messing with OpenSSL.
- 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
- I. Convert PEM files
- PEM to DER
- openssl x509 -outform der -in certificate.pem -out certificate.der
- PEM to P7B
- openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer
- PEM to PFX
- openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt
- II. Convert P7B files
- P7B to PEM
- openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
- P7B to PFX
- openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
- openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer
- III. Convert PFX files
- PFX to PEM
- openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes konwersja poprze OpenSSL
- IV. Convert DER files
- DER to PEM
- openssl x509 -inform der -in certificate.cer -out certificate.pem
- KEY Gen
- $ openssl genrsa 2048 > mfapola.key
- CSR Gen
- $ openssl req -new -key mfapola.key > mfapola.csr
- $ openssl req -nodes -newkey rsa:2048 -sha1 -keyout mydomain.key -out mydomain.csr
- Sign CRT
- $ openssl x509 -req -days 3650 -signkey mfapola.key < mfapola.csr > mfapola.crt
- Change type SSL cert from pkcs12(.pfx) to CER(PEM)
- $ conv to pkcs12 from cer/crt
- $ openssl pkcs12 -export -out test.pfx -inkey mfapola.key -in mfapola.crt
- Other
- $ openssl x509 -noout -text -in
- $ openssl x509 -noout -issuer -subject -dates -modulus -in
- $ openssl req -noout -text -in
- $ openssl req -noout -subject -modulus -in
- $ openssl rsa -noout -text -in
- $ openssl rsa -noout -modulus -in
- For symmetic encryption, you can use the following:
- To encrypt:
- openssl aes-256-cbc -salt -a -e -in plaintext.txt -out encrypted.txt
- To decrypt:
- openssl aes-256-cbc -salt -a -d -in encrypted.txt -out plaintext.txt
- For Asymmetric encryption you must first generate your private key and extract the public key.
- openssl genrsa -aes256 -out private.key 8912
- openssl -in private.key -pubout -out public.key
- To encrypt:
- openssl rsautl -encrypt -pubin -inkey public.key -in plaintext.txt -out encrypted.txt
- To decrypt:
- openssl rsautl -decrypt -inkey private.key -in encrypted.txt -out plaintext.txt
- Source: http://bsdsupport.org/2007/01/q-how-do-i-use-openssl-to-encrypt-files/
- =============================================================================================================
- You can't directly encrypt a large file using rsautl. instead, do something like the following:
- Generate a key using openssl rand, eg. openssl rand 32 -out keyfile
- Encrypt the key file using openssl rsautl
- Encrypt the data using openssl enc, using the generated key from step 1.
- Package the encrypted key file with the encrypted data. the recipient will need to decrypt the key with their private key, then decrypt the data with the resulting key.
- Ultimate solution for safe and high secured encode anyone file in OpenSSL and command-line:
- You should have ready some X.509 certificate for encrypt files in PEM format.
- NOTE: You can generated a X.509 certificate using:
- Private key generation (encrypted private key):
- openssl genrsa -aes256 -out private.pem 8912
- openssl -in private.pem -pubout -out public.pem
- With unecrypted private key:
- openssl req -x509 -nodes -days 100000 -newkey rsa:8912 -keyout private_key.pem -out certificate.pem
- With encrypted private key:
- openssl req -x509 -days 100000 -newkey rsa:8912 -keyout private_key.pem -out certificate.pem
- With existing encrypted (unecrypted) private key:
- openssl req -x509 -new -days 100000 -key private_key.pem -out certificate.pem
- To encrypt:
- openssl smime -encrypt -binary -aes-256-cbc -in plainfile.zip -out encrypted.zip.enc -outform PEM yourSslCertificate.pem
- openssl smime -encrypt -binary -aes-256-cbc -in plainfile.zip -out encrypted.zip.enc -outform DER yourSslCertificate.pem
- For text files:
- openssl smime -encrypt -aes-256-cbc -in input.txt -out output.txt -outform DER yourSslCertificate.pem
- openssl smime -encrypt -aes-256-cbc -in input.txt -out output.txt -outform PEM yourSslCertificate.pem
- What is what:
- smime - ssl command for S/MIME utility (smime(1))
- -encrypt - chosen method for file process
- -binary - use safe file process. Normally the input message is converted to "canonical" format as required by the S/MIME specification, this switch disable it. It is necessary for all binary files (like a images, sounds, ZIP archives).
- -aes-256-cbc - chosen cipher AES in 256 bit for encryption (strong). If not specified 40 bit RC2 is used (very weak). (Supported ciphers)
- -in plainfile.zip - input file name
- -out encrypted.zip.enc - output file name
- -outform DER - encode output file as binary. If is not specified, file is encoded by base64 and file size will be increased by 30%.
- yourSslCertificate.pem - file name of your certificate's. That should be in PEM format.
- That command can very effectively a strongly encrypt any file regardless of its size or format.
- To decrypt:
- openssl smime -decrypt -binary -in encrypted.zip.enc -inform DER -out decrypted.zip -inkey private.key -passin pass:your_password
- openssl smime -decrypt -binary -in encrypted.zip.enc -inform PEM -out decrypted.zip -inkey private.key -passin pass:your_password
- For text files:
- openssl smime -decrypt -in encrypted_input.txt -inform DER -out decrypted_input.zip -inkey private.key -passin pass:your_password
- openssl smime -decrypt -in encrypted_input.txt -inform PEM -out decrypted_input.zip -inkey private.key -passin pass:your_password
- What is what:
- -inform DER - same as -outform above
- -inkey private.key - file name of your private key. That should be in PEM format and can be encrypted by password.
- -passin pass:your_password - your password for private key encrypt. (http://www.openssl.org/docs/apps/openssl.html#PASS_PHRASE_ARGUMENTS)
- Generating public key from private key:
- openssl rsa -in private_key.pem -pubout > public_key.pem
- Creating a signed digest of a file:
- openssl dgst -sha512 -sign private_key.pem -out digest.sha512 file.txt
- Verify a signed digest:
- openssl dgst -sha512 -verify public_key.pem -signature digest.sha512 file.txt
- Source: http://stackoverflow.com/questions/7143514/how-to-encrypt-a-large-file-in-openssl-using-public-key
- http://www.madboa.com/geek/openssl/
- http://stackoverflow.com/questions/5140425/openssl-command-line-to-verify-the-signature
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement