char* my3DesCBC_Decode_default(char *in_24char_CipherTxt,char *out_32char_PlainTxt)
{
int xLen =24; //default:24;
int len001 = 0;
unsigned char *res_PlainTxt;
unsigned char *res_decode_Base64;
base64_de((unsigned char*)in_24char_CipherTxt,&res_decode_Base64,&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,&res_PlainTxt,&xLen) == RESULT_OK)
{
xLen = xLen >30 ? 30 : xLen; //xLen是解密后的字串真實長度,我的應用中實際上最長不超過14字符;
snprintf(out_32char_PlainTxt ,xLen+0,"%s",res_PlainTxt); //xLen+1; 疑惑: 這里不應該+1么?這個函式自己加1個'\0'的啊?現實當中,+1是錯誤的,不加反而是正確的……郁悶了。經過測驗居然發現它并沒有加'\0',而我以往一直用著這個函式復制字串好好的。然而我再單獨寫一個測驗函式,用snprintf()復制字串,長度+1是正確的。只有這個函式中,似乎snprintf不會加‘\0’,無法定位例外,請高手幫助
len001 = strlen(out_32char_PlainTxt);
printf("3DES CBC DECODE:%s ;Len=%d,%d\n",out_32char_PlainTxt,xLen,len001);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/30841.html
標籤:基礎類
下一篇:基于laravel制作API介面
