Home > Back-end >  Meet the snprintf () doubt!
Meet the snprintf () doubt!

Time:11-12

Char * my3DesCBC_Decode_default (char * in_24char_CipherTxt, char * out_32char_PlainTxt)
{
Int xLen=24;//the default: 24;
Int len001=0;
Unsigned char * res_PlainTxt;
Unsigned char * res_decode_Base64;

Base64_de ((unsigned char *) in_24char_CipherTxt, & amp; Res_decode_Base64, & amp; XLen);
//printf (" Base64 decode: ");
//printHex (res_decode_Base64 xLen);
//printf (" \ n ");

If (des_decode (DES3_CBC, pmingKey16_default pmingKeyLen_default, pmingVI008_default, res_decode_Base64, & amp; Res_PlainTxt, & amp; XLen)==RESULT_OK)
{
XLen=xLen & gt; 30? 30: xLen;//xLen is decrypted string length, of my application, in fact, the longest do not exceed 14 characters;
Snprintf (out_32char_PlainTxt xLen + 0, "% s", res_PlainTxt);//xLen + 1; wondering: should not + 1 here? this function yourself add 1 '\ 0'? Reality, instead of + 1 is a mistake, do not add is right... Depressed, tested was found that it did not add '\ 0', and I in the past have been use this function to copy a string thoroughly, but I'll write a test function alone, with snprintf () copy the string, the length + 1 is right, only this function, seems snprintf not add '\ 0', can't locate abnormal, please help
Len001=strlen (out_32char_PlainTxt);
Printf (" 3 des CBC DECODE: % s. Len=% d, % d \ n ", out_32char_PlainTxt, xLen, len001);
}
}
  • Related