code_junkie

Problem with OpenSSL library

Nov 13th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. RSA *_RSA ;
  2. unsigned char text[2560] = "A";
  3. unsigned char sectext[2560];
  4. unsigned char decrypttext[2560];
  5. int i = 0;
  6.  
  7. _RSA = RSA_generate_key ( 1024, 65537, NULL, NULL );
  8. i = RSA_public_encrypt ( 1, text, sectext, _RSA, RSA_PKCS1_OAEP_PADDING );
  9. i = RSA_private_decrypt( 1, sectext, decrypttext, _RSA, RSA_PKCS1_OAEP_PADDING);
  10. RSA_free ( _RSA );
  11.  
  12. 128 from encrypt.
  13. 1 from decrypt: 'A'
  14.  
  15. #include <openssl/rsa.h>
  16. #include <openssl/engine.h>
  17. #include <stdio.h>
  18.  
  19. int main(int argc, char **argv)
  20. {
  21. RSA *myRSA;
  22. unsigned char cleartext[2560] = "A";
  23. unsigned char encrypted[2560] = { 0 };
  24. unsigned char decrypted[2560] = { 0 };
  25. int resultEncrypt = 0;
  26. int resultDecrypt = 0;
  27.  
  28. myRSA = RSA_generate_key ( 1024, 65537, NULL, NULL );
  29. resultEncrypt = RSA_public_encrypt ( 1 /* strlen(cleartext) */, cleartext, encrypted, myRSA, RSA_PKCS1_OAEP_PADDING );
  30. printf("%d from encrypt.n", resultEncrypt);
  31. resultDecrypt = RSA_private_decrypt( 128 /* resultEncrypt */, encrypted, decrypted, myRSA, RSA_PKCS1_OAEP_PADDING);
  32. printf("%d from decrypt: '%s'n", resultDecrypt, decrypted);
  33. RSA_free ( myRSA );
  34.  
  35. return 0;
  36. }
Add Comment
Please, Sign In to add comment