RSA Security Projection Television 5.2.2 Uživatelský manuál Strana 204

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 376
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 203
Block Ciphers
182 RSA BSAFE Crypto-C Developers Guide
Now that you have a key, you need an algorithm chooser and a surrender context.
This is a speedy function, so you can use a properly cast
NULL_PTR for the surrender
context; but you do want to build a chooser:
Step 4: Update
Enter the data to encrypt with B_EncryptUpdate. The Reference Manual Chapter 2 entry
for
AI_FeedbackCipher states that you may pass (B_ALGORITHM_OBJ)NULL_PTR for all
randomAlgorithm
arguments. Once you have your input, call B_EncryptUpdate.
Remember that DES is a block cipher and requires input that is a multiple of eight
bytes. Because you set
fbParams.paddingMethodName
to "pad" (see page 180), Crypto-
C will pad to make the input a multiple of eight bytes. That means that the output
buffer should be at least eight bytes longer than the input length. DES is a fast
algorithm, so for small amounts of data it is reasonable to pass a properly cast
NULL_PTR for the surrender context. If you want to pass a surrender context, refer to
the following code sample:
B_ALGORITHM_METHOD *DES_CBC_CHOOSER[] = {
&AM_CBC_ENCRYPT,
&AM_DES_ENCRYPT,
&AM_SHA_RANDOM,
(B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_EncryptInit
(encryptionObject, desKey, DES_CBC_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
static char *dataToEncrypt = "Encrypt this sentence.";
unsigned char *encryptedData = NULL_PTR;
unsigned int outputBufferSize;
unsigned int outputLenUpdate, outputLenFinal;
unsigned int encryptedDataLen;
encryptedDataLen = dataToEncryptLen + 8;
encryptedData = T_malloc (encryptedDataLen);
if ((status = (encryptedData == NULL_PTR)) != 0)
break;
Zobrazit stránku 203
1 2 ... 199 200 201 202 203 204 205 206 207 208 209 ... 375 376

Komentáře k této Příručce

Žádné komentáře