Remove unwanted/dummy character in C language
I’ve encounter this issue in RSA decryption (RSA_private_decrypt
)
1 | int result_length = RSA_private_decrypt(64, (unsigned char*)crypt_chunk, (unsigned char *)result_chunk, rsa_privateKey, RSA_PKCS1_PADDING); |
Output
1 | Result chunk: 33-9998-123-123408101123451250-PARADM01_00023054-CY00\240Z |
But what I want is 33-9998-123-123408101123451250-PARADM01_00023054-CY00
I googled for some time still can’t get the result. By try-and-error method, I solved this by adding the following code
1 | char tmp_result[result_length + 1]; |
Output
1 | New chunk: 33-9998-123-123408101123451250-PARADM01_00023054-CY00 |
- Declaring a new variable with additional 1 more character of the original result
- Copy the original result to the new variable
- Inject a
null
character to the end of the new variable
Hope this helps. :)