Code Example

6 RSA BSAFE Crypto-C Library Reference Manual

The main work in
EncryptData
is done by the functions B_EncryptInit,
B_EncryptUpdate, and B_EncryptFinal. The calling format for these and other
functions is shown in Chapter 4, “Details of Crypto-C Functions.” Most Crypto-C procedures return either a zero for success or one of the error types listed in Appendix A.
if ((status = B_CreateAlgorithmObject (&desAlgorithm)) != 0)
break;
initVector.data = iv;
initVector.len = 8;
feedbackParams.encryptionMethodName = “des”;
feedbackParams.encryptionParams = NULL_PTR;
feedbackParams.feedbackMethodName = “cbc”;
feedbackParams.feedbackParams = initVector;
feedbackParams.paddingMethodName = “pad”;
feedbackParams.paddingParams = NULL_PTR;
if ((status = B_SetAlgorithmInfo
(desAlgorithm, (POINTER)&AI_FeedbackCipher,
(POINTER)&feedbackParams)) != 0)
break;
if ((status = B_EncryptInit
(desAlgorithm, desKey, DEMO_ALGORITHM_CHOOSER,
NULL_SURRENDER_PTR)) != 0)
break;
if ((status = B_EncryptUpdate
(desAlgorithm, output, outputLen, maxOutputLen, input,
inputLen, (B_ALGORITHM_OBJ)NULL_PTR,
NULL_SURRENDER_PTR)) != 0)
break;
if ((status = B_EncryptFinal
(desAlgorithm, output + *outputLen, &partOutLen,
maxOutputLen - *outputLen, (B_ALGORITHM_OBJ)NULL_PTR,
NULL_SURRENDER_PTR)) != 0)
break;
*outputLen += partOutLen;
} while (0);
B_KEY_OBJ desKey = (B_KEY_OBJ)NULL_PTR;
B_ALGORITHM_OBJ desAlgorithm = (B_ALGORITHM_OBJ)NULL_PTR;
return (status);
}