-1

i'm using this portion of code

char encrypted_text[1024];
RSA_public_encrypt(sizeof(message), message, encrypted_text, rsa, RSA_PKCS1_OAEP_PADDING);
printf("encrypted text: %s\n", encrypted_text);

and the optput is something like this:

�v0��뷾��s�E�Z��N\����6~��:�&���� /����~ͯ���L��d�Ǡ�� E��[�h�U.vH2F1Qb^)�g� ,a�Ҩ�x vU|�>�ˢ=W�ő�� �\��g

it's possible to eliminate � symbols??

giozh
  • 9,868
  • 30
  • 102
  • 183
  • 1
    The cyphertext isn't meant to be human-readable. Nor even intelligible as characters in a text encoding like UTF-8. Certainly you can eliminate the unknown-character symbols. But to do so, you'll first have to decide: what is it you're trying to accomplish by printing it? – Managu Aug 18 '12 at 16:17
  • i would print it just for watch what happen when i'm encrypt something, a sort of visual log – giozh Aug 18 '12 at 16:27

1 Answers1

5

The string isn't printing well because it's binary data, not text. It's not meant to be human readable.

A common way to make binary data text-friendly is to base64 encode it. Base64 encoding converts binary data into a string of ASCII characters. The encoded text still isn't human readable, so it'll still look like gobbledygook when you print it, but it'll at least be easy on the eyes, easy to paste into text files, easy to e-mail around.

See this Stack Overflow question for ways to do base64 encoding/decoding in C.

Community
  • 1
  • 1
John Kugelman
  • 349,597
  • 67
  • 533
  • 578