> For the complete documentation index, see [llms.txt](https://jacky-chen.gitbook.io/jackychen/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jacky-chen.gitbook.io/jackychen/dai-fen-lei/openssl.md).

# OpenSSL

* [**Use RSA with OpenSSL on Mac**](https://stackoverflow.com/questions/29010967/openssl-unable-to-load-public-key)
* Generate RSA key:

  ```
  $ openssl genrsa -out key.pem 1024
  ```
* Save public key in pub.pem file:

  ```
  $ openssl rsa -in key.pem -pubout -out pub.pem
  ```
* Encrypt some data:

  ```
  $ echo test test test > file.txt 
  $ openssl rsautl -encrypt -inkey pub.pem -pubin -in file.txt -out file.bin
  ```
* Decrypt encrypted data:

  ```
  openssl rsautl -decrypt -inkey key.pem -in file.bin
  ```
