title: RSA_Private_Decrypt fails randomly
body: <p>I am not a crypto expert, but I wrote encrypt/decrypt methods. I don't know what I am doing wrong here. The <strong>encryptKey</strong> method returns the variable text length every time for the same string, which is may be due to RSA_PKCS1_PADDING which I am using, but for same string of text, the <strong>decryptKey</strong> function fails if the encrypted text length is below some threshold.<br></p>
  
  <pre><code>//----------------------Encryption -----------------------
  int Asymmetric::encryptKey(unsigned char *data, int data_len, unsigned char *encrypted)
  {
      RSA * rsa = createRSA(1); // Loads the public key
      int result = RSA_public_encrypt(data_len,data,encrypted,rsa,padding);
      return result;
  }
  //-----------------------Decryption -----------------------
  int Asymmetric::decryptKey(unsigned char * enc_data,int data_len, unsigned char *decrypted)
  {
      RSA * rsa = createRSA(0); // Loads the private key
      int  result = RSA_private_decrypt(data_len,enc_data,decrypted,rsa,padding);
      return result;
  }
  </code></pre>
  
  <p>How i can overcome this situation?</p>
  
  <p><strong>Edit</strong>: <br>
  This code does not work <br></p>
  
  <pre><code>char *myData = "Sample Text";
  unsigned char *encrypt = (unsigned char*)malloc(RSA_size(rsaPub));
  int result = RSA_public_encrypt(RSA_size(rsaPub)-11 ,(unsigned char*)myData,encrypt,rsaPub,padding);
  fprintf(stderr, "\nEnc Size: %d \n", strlen((const char*)encrypt));
  </code></pre>