0

Ok i've got this simple code to encrypt a msg with a private key. When i run the app it crashes. Any help?

#include <stdio.h>
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>

int main()
{
  char keyy[] = "Private key here";
  unsigned char *key = (unsigned char* )keyy;
  printf("%d\n",sizeof(keyy));
  RSA *public_key = d2i_RSAPrivateKey(NULL, (const unsigned char**)&key, 1589);
  char message[] = "magic";
  unsigned char *encrypted = (unsigned char *) malloc(5000);
  unsigned char *decrypted = (unsigned char *) malloc(5000);
  printf("%s\n",key);
  RSA_private_encrypt(strlen(message), (unsigned char *) message, encrypted, public_key, RSA_PKCS1_PADDING); // crashes here
  return 0;
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by daviddoria
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.