R
rtillmore
Hi,
I have run into a small snag with a program I am writing. I am
generating a string using openssl DES_ecb_encrypt. The string is
properly generated and contains the correct value. The problem is
that one of the generated strings contains null in the middle so when
I use strcat to append the generated string to the rest of the key I
am losing the bytes after the NULL. Here is my code:
for (i=0, j=0; i<=64; i+=8) {
strncpy((char*)enc_block,(char*)&encrypteddata, 8);
strncpy((char*)block_key,(char*)&seckey[j], 7);
str_to_key(block_key,des_key);
DES_set_key_checked((des_cblock *)des_key, &ks1);
DES_ecb_encrypt((des_cblock *)enc_block, (des_cblock *)temphold,
&ks1, DES_DECRYPT);
j += 7;
if (strlen((char*)&seckey[j]) <7) {
j = strlen((char*)&seckey[j]);
printf("j = %d\n",j);
}
strcat((char*)output1,(char*)temphold);
}
The key causing the problem is when temphold = b0 71 ba d5 00 93 9a b7
(I can't paste the char string). So when the program gets to the
strcat b0 71 ba d5 is copied and the rest is dropped causing problems
down the line. How can I work around this?
Thanks,
I have run into a small snag with a program I am writing. I am
generating a string using openssl DES_ecb_encrypt. The string is
properly generated and contains the correct value. The problem is
that one of the generated strings contains null in the middle so when
I use strcat to append the generated string to the rest of the key I
am losing the bytes after the NULL. Here is my code:
for (i=0, j=0; i<=64; i+=8) {
strncpy((char*)enc_block,(char*)&encrypteddata, 8);
strncpy((char*)block_key,(char*)&seckey[j], 7);
str_to_key(block_key,des_key);
DES_set_key_checked((des_cblock *)des_key, &ks1);
DES_ecb_encrypt((des_cblock *)enc_block, (des_cblock *)temphold,
&ks1, DES_DECRYPT);
j += 7;
if (strlen((char*)&seckey[j]) <7) {
j = strlen((char*)&seckey[j]);
printf("j = %d\n",j);
}
strcat((char*)output1,(char*)temphold);
}
The key causing the problem is when temphold = b0 71 ba d5 00 93 9a b7
(I can't paste the char string). So when the program gets to the
strcat b0 71 ba d5 is copied and the rest is dropped causing problems
down the line. How can I work around this?
Thanks,