Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Forked from zhiguangwang/openssl.md
Last active October 10, 2024 12:03
Show Gist options
  • Save NoMan2000/06fffaca2ea710175cbcdd1a933c44af to your computer and use it in GitHub Desktop.
Save NoMan2000/06fffaca2ea710175cbcdd1a933c44af to your computer and use it in GitHub Desktop.

Revisions

  1. NoMan2000 revised this gist Mar 1, 2017. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions openssl.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,14 @@
    ## Common OpenSSL Commands with Keys and Certificates

    [SSL Info](https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs)

    ### Generate RSA private key with certificate in a single command
    openssl req -x509 -newkey rsa:4096 -sha256 -keyout example.key -out example.crt -subj "/CN=example.com" -days 3650 -passout pass:foobar

    ### Generate Certificate Signing Request (CSR) from private key with passphrase

    openssl x509 -x509toreq -in example.crt -out example.csr -signkey example.key -passin pass:foobar

    #### Generate RSA private key (2048 bit)

    openssl genrsa -out private.pem 2048
  2. @zhiguangwang zhiguangwang revised this gist Nov 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion openssl.md
    Original file line number Diff line number Diff line change
    @@ -42,4 +42,4 @@

    #### Convert a PEM file to DER

    openssl x509 -outform der -in certificate.pem -out certificate.der
    openssl x509 -outform der -in certificate.pem -out certificate.cer
  3. @zhiguangwang zhiguangwang revised this gist Oct 31, 2015. 2 changed files with 45 additions and 20 deletions.
    45 changes: 45 additions & 0 deletions openssl.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    ## Common OpenSSL Commands with Keys and Certificates

    #### Generate RSA private key (2048 bit)

    openssl genrsa -out private.pem 2048

    #### Generate a Certificate Signing Request (CSR)

    openssl req -sha256 -new -key private.pem -out csr.pem

    #### Generate RSA private key (2048 bit) and a Certificate Signing Request (CSR) with a single command

    openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr

    #### Convert private key to PEM format

    openssl rsa -in server.key -outform PEM -out server.pem

    #### Generate a self-signed certificate that is valid for a year with sha256 hash

    openssl x509 -req -sha256 -days 365 -in csr.pem -signkey private.pem -out certificate.pem

    #### View details of a RSA private key

    openssl rsa -in private.pem -text -noout

    #### View details of a CSR

    openssl req -in csr.pem -text -noout

    #### View details of a Certificate

    openssl x509 -in certificate.pem -text -noout

    #### View details of a Certificate in DER format

    openssl x509 -inform der -in certificate.cer -text -noout

    #### 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
    20 changes: 0 additions & 20 deletions openssl.sh
    Original file line number Diff line number Diff line change
    @@ -1,20 +0,0 @@
    # Generate RSA private key (2048 bit)
    openssl genrsa -out private.pem 2048

    # Generate a Certificate Signing Request (CSR)
    openssl req -sha256 -new -key private.pem -out csr.pem

    # Generate a self-signed certificate that is valid for a year with sha256 hash
    openssl x509 -req -sha256 -days 365 -in csr.pem -signkey private.pem -out certificate.pem

    # View details of a RSA private key
    openssl rsa -in private.pem -text -noout

    # View details of a CSR
    openssl req -in csr.pem -text -noout

    # View details of a Certificate
    openssl x509 -in certificate.pem -text -noout

    # View details of a Certificate in DER format
    openssl x509 -inform der -in certificate.cer -text -noout
  4. @zhiguangwang zhiguangwang created this gist Jun 5, 2015.
    20 changes: 20 additions & 0 deletions openssl.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # Generate RSA private key (2048 bit)
    openssl genrsa -out private.pem 2048

    # Generate a Certificate Signing Request (CSR)
    openssl req -sha256 -new -key private.pem -out csr.pem

    # Generate a self-signed certificate that is valid for a year with sha256 hash
    openssl x509 -req -sha256 -days 365 -in csr.pem -signkey private.pem -out certificate.pem

    # View details of a RSA private key
    openssl rsa -in private.pem -text -noout

    # View details of a CSR
    openssl req -in csr.pem -text -noout

    # View details of a Certificate
    openssl x509 -in certificate.pem -text -noout

    # View details of a Certificate in DER format
    openssl x509 -inform der -in certificate.cer -text -noout