入力データをプレーンテキストとして受け取り、CBCモードで3DESメソッドを使用してメッセージを復号化するプログラムがあります。しかし、値はプログラムにハードコーディングされています。暗号化された値を自分で提供したいので、それを解読する必要があります。次のプログラムでこれを行うにはどうすればよいですか?
int main(void)
{
unsigned char in[BUFSIZE], out[BUFSIZE], back[BUFSIZE];
unsigned char *e = out;
int len;
DES_cblock key;
DES_cblock seed = {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10};
DES_cblock ivsetup = {0xE1, 0xE2, 0xE3, 0xD4, 0xD5, 0xC6, 0xC7, 0xA8};
DES_key_schedule keysched;
DES_cblock ivec;
memset(in, 0, sizeof(in));
memset(out, 0, sizeof(out));
memset(back, 0, sizeof(back));
RAND_seed(seed, sizeof(DES_cblock));
DES_random_key(&key);
DES_set_odd_parity(&key);
if (DES_set_key_checked((C_Block *)key, &keysched))
{
fprintf(stderr, "ERROR: Unable to set key schedule\n");
exit(1);
}
/* 64 bytes of plaintext */
/* From here, encryption starts for the plaintext below. */
strcpy(in, "Now is the time for all men to stand up and be counted");
printf("Plaintext: [%s]\n", in);
len = strlen(in);
memcpy(ivec, ivsetup, sizeof(ivsetup));
DES_ncbc_encrypt(in, out, len, &keysched, &ivec, DES_ENCRYPT);
printf("Ciphertext:");
while (*e) printf(" [%02x]", *e++);
printf("\n");
/* Till here, encryption is over. After this we have to decrypt
* the value which has been encoded, but I want to remove all this
* part and to provide my own encrypted message, and get the
* proper output.
*/
memcpy(ivec, ivsetup, sizeof(ivsetup));
/* The problem I am facing is how to provide the value properly
* to the parameter "out" and "keysched", which should be of my
* choice. For "out" I want to provide THIS value:
* "2DC39619B4450A8C27A3976C50DE5799".
*/
DES_ncbc_encrypt(out, back, len, &keysched, &ivec, DES_DECRYPT);
printf("Decrypted Text: [%s]\n", back);
exit(0);
}
続きを読む: http: //blog.fpmurphy.com/2010/04/openssl-des-api.html#ixzz1uqOp1Yhv