<div dir="ltr">Hi Marcus,<div><br></div><div>The encrypt_private is doing an RSA encryption using PKCS1 padding by default.</div><div><br></div><div>RSA can't encrypt large payloads (i.e. 256 bytes - 11 for padding for 2048 bit RSA keys) so this is the likely reason you can only encrypt small portions of the file.<br></div><div><br></div><div>Normally you use public key crypto to encrypt a symmetrical key and then encrypt the large payload with the symmetric key using AES or something.</div><div><br></div><div>In addition you don't want to encrypt using the private key but rather the public key, otherwise anyone with access to your public key can decrypt the cipher. Private key encryption is usually only used for signatures.</div><div><br></div><div>Crypto is hard to get right, especially if you are only working with RSA primitives (you need to think about padding, hashing, MDCs, signatures). You might want to have a look a NaCl (<a href="https://github.com/jloius/enacl">https://github.com/jloius/enacl</a> for a binding to erlang) which is much friendlier to use.</div><div><br></div><div>Cheers,</div><div>Martin</div><div><br></div><div><br>On Tuesday, 14 April 2015, Marcus Nilsson <<a href="mailto:tandy.nilsson@gmail.com" target="_blank">tandy.nilsson@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div>I'am trying to encrypt a bigger file with the public_key module. Everything works fine as long as the content of the file is small.<br><br></div>But when the size of the binary exceed's a certain size I get a **error:encrypt_failed. I guess this has to do with the padding parameter.<br><br></div>But I have not been able to find any documentation how to compute the padding to get this working any help would be very welcomed!<br><br>I use this code to perform the encryption<br><br>public_key:encrypt_private(Input, PrivKey);<br><br></div>/Marcus<br></div>
</blockquote></div>
</div>