title: Laravel 5.6 and TCPDF Public Key Encryption
body: <p>I am new to PKI and was hoping someone could help me with my situation. I am currently using Laravel 5.6 to develop my site and I am using the <code>elibyy/tcpdf-laravel</code> package for creating PDF's. Currently, when my users create the PDF it is encrypted via AES 256 and password protected but I would like to add public key encryption.</p>
  
  <p>Here's is the process, a contract is created via HTML, the user signs the contract, once signed a checkbox appears and a finish button. They check the box and click finish. The webpage is then converted to a PDF and stored on AWS S3.</p>
  
  <p>The following is in the documentation for TCPDF about Public Key Encryption:</p>
  
  <pre><code> Possible encryption modes are:
   0 = RSA 40 bit
   1 = RSA 128 bit
   2 = AES 128 bit
   3 = AES 256 bit
  
  
  
  NOTES:
   - To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
   - To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
   - To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  
  */
  
  $pdf-&gt;SetProtection(array('print', 'copy'), '', null, 0, null);
  
  // Example with public-key
  // To open the document you need to install the private key (tcpdf.p12) on the Acrobat Reader. The password is: 1234
  //$pdf-&gt;SetProtection($permissions=array('print', 'copy'), $user_pass='', $owner_pass=null, $mode=1, $pubkeys=array(array('c' =&gt; 'file://../config/cert/tcpdf.crt', 'p' =&gt; array('print'))));
  
  // *********************************************************
  </code></pre>
  
  <p>Question One: Where do I store the public and private keys? In my Laravel App? On AWS S3?</p>
  
  <p>Question Two: Do I need to generate a public key for each contract?</p>
  
  <p>Question Three: It says to open a document you have to install the private key on Acrobat Reader, I assume this is something the user would have to do in order to open the PDF?</p>
  
  <p>I was hoping there was a tutorial on this, but I can't seem to find one. Any help is greatly appreciated. Thank you!</p>