Skip to content

Instantly share code, notes, and snippets.

@gubi
Forked from carlj/rsa-encryption.md
Last active December 28, 2015 16:58
Show Gist options
  • Select an option

  • Save gubi/7532110 to your computer and use it in GitHub Desktop.

Select an option

Save gubi/7532110 to your computer and use it in GitHub Desktop.

Revisions

  1. gubi revised this gist Nov 18, 2013. No changes.
  2. gubi revised this gist Nov 18, 2013. No changes.
  3. @carlj carlj renamed this gist Sep 10, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @carlj carlj revised this gist Sep 10, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -46,3 +46,5 @@ openssl rsautl -decrypt -inkey private.pem -in aesKey.txt.crypted -out aesKey.tx
    openssl enc -d -aes-256-cbc -in file.enc -out file.txt.decrypted -pass file:./aesKey.txt.decrypted
    ```

    ##Source
    [Public – Private key encryption using OpenSSL](http://www.devco.net/archives/2006/02/13/public_-_private_key_encryption_using_openssl.php)
  5. @carlj carlj revised this gist Sep 10, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ openssl rsa -in private.pem -out public.pem -outform PEM -pubout

    ###Generate AES Key
    ```
    //generate a Radnom 32 Byte AES Key
    //generate a Radnom 32 Byte (256 Bit) AES Key
    openssl rand -base64 32 -out aesKey.txt
    ```

  6. @carlj carlj revised this gist Sep 10, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ openssl rsa -in private.pem -out public.pem -outform PEM -pubout
    ###Generate AES Key
    ```
    //generate a Radnom 32 Byte AES Key
    openssl rand -base64 32 > aesKey.txt
    openssl rand -base64 32 -out aesKey.txt
    ```

    ##Encryption
  7. @carlj carlj created this gist Sep 10, 2013.
    48 changes: 48 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    #RSA File De- and Encryption
    Docu for encrypt and decrypt a large file with AES and RSA

    ##Keypairs

    ###Generate RSA Keypairs
    ```
    //generates a private Key with 8196 Bit
    openssl genrsa -out private.pem 8196
    //strips out the public key from the private key
    openssl rsa -in private.pem -out public.pem -outform PEM -pubout
    ```

    ###Generate AES Key
    ```
    //generate a Radnom 32 Byte AES Key
    openssl rand -base64 32 > aesKey.txt
    ```

    ##Encryption

    ###Encrypt File with AES Key
    ```
    //encryp the file.txt with the generated AES Key to the file.enc
    openssl enc -aes-256-cbc -salt -in file.txt -out file.enc -pass file:./aesKey.txt
    ```

    ###Encrypt AES Key with RSA Public Key
    ```
    //encrpyt the AES Key with the RSA Public Key
    openssl rsautl -encrypt -inkey public.pem -pubin -in aesKey.txt -out aesKey.txt.crypted
    ```

    ##Decryption

    ###Decrypt AES Key with RSA Private Key
    ```
    //decrypt the AES Key with the Private RSA Key
    openssl rsautl -decrypt -inkey private.pem -in aesKey.txt.crypted -out aesKey.txt.decrypted
    ```

    ###Decryp File with AES Key
    ```
    //decrypt the encrypted file with the encrypted AES Key
    openssl enc -d -aes-256-cbc -in file.enc -out file.txt.decrypted -pass file:./aesKey.txt.decrypted
    ```