RSA Security 5.2.2 manual If encryptedData != Nullptr, EncryptedData = Nullptr End main

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 47
Image 47

Introductory Example

if (encryptedData != NULL_PTR){

T_memset (encryptedData, 0, dataToEncryptLen); T_free (encryptedData);

encryptedData = NULL_PTR;

}

} /* end main */

You may find it a useful exercise to compile and link this program. Also, it could also be instructive to add some print statements. For instance, what are the values of outputLenUpdate and outputLenFinal?

While it is possible to print the encryptedData, it will not be an ASCII string — it is not any kind of string, because there is no NULL-terminating character. The encrypted data is binary data, so it may be more useful to print out the result byte-by-byte in hex- ASCII strings. For an example of a function that does this, see the RSA_PrintBuf() routine in samples/common/source/demoutil.c. In addition, note that when writing Crypto-C output to (and reading it from) files, it is usually more useful (in some cases, even necessary) to open the files in binary mode.

To run this exercise, first compile introex.c and tstdlib.c. You can find makefiles in the samples/make directory. Then link the object files with bsafe.lib or the equivalent platform-specific library.

C h a p t e r 2 Q u i c k S t a r t

2 5

Page 47
Image 47
RSA Security 5.2.2 manual If encryptedData != Nullptr, EncryptedData = Nullptr End main