我使用以下代码使用openssl在Windows中使用C加密和解密二进制数据。如您所见,在两个函数中,我都知道纯文本的大小。有没有办法在不知道纯文本大小的情况下解密邮件?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/des.h>
char * Encrypt(char *Key, char *Msg, int size)
{
static char* Res;
int n = 0;
DES_cblock Key2;
DES_key_schedule schedule;
Res = (char *)malloc(size);
/* Prepare the key for use with DES_cfb64_encrypt */
memcpy(Key2, Key, 8);
DES_set_odd_parity(&Key2);
DES_set_key_checked(&Key2, &schedule);
/* Encryption occurs here */
DES_cfb64_encrypt((unsigned char *)Msg, (unsigned char *)Res,size, &schedule, &Key2, &n, DES_ENCRYPT);
return (Res);
}
char * Decrypt(char *Key, char *Msg, int size)
{
static char* Res;
int n = 0;
DES_cblock Key2;
DES_key_schedule schedule;
Res = (char *)malloc(size);
/* Prepare the key for use with DES_cfb64_encrypt */
memcpy(Key2, Key, 8);
DES_set_odd_parity(&Key2);
DES_set_key_checked(&Key2, &schedule);
/* Decryption occurs here */
DES_cfb64_encrypt((unsigned char *)Msg, (unsigned char *)Res,size, &schedule, &Key2, &n, DES_DECRYPT);
return (Res);
}
int _tmain(int argc, _TCHAR* argv[])
{
char key[] = "password";
char clear[] = "This is a secret message";
char *decrypted;
char *encrypted;
encrypted = (char *)malloc(sizeof(clear));
decrypted = (char *)malloc(sizeof(clear));
printf("Clear text\t : %s : sizeof: %i\n", clear, strlen (clear));
memcpy(encrypted, Encrypt(key, clear, sizeof(clear)), sizeof(clear));
printf("Encrypted text\t : %s sizeof: %i\n", encrypted, strlen(encrypted));
memcpy(decrypted, Decrypt(key, encrypted, sizeof(clear)), sizeof(clear));
printf("Decrypted text\t : %s sizeof: %i\n", decrypted, strlen(decrypted));
return 0;
}
答案 0 :(得分:0)
只有密码反馈?当然,只要你知道块边界在哪里就是黄金(即你需要知道你在密文中的哪个)。