The encrypted.file is exactly as the original.

Thanks in advance,
julian

void aes::encrypt_file(const char * key, const char * path,
    unsigned char * buf /*[in|out]*/)
{
    // ...
    unsigned char fbuf_in[1024];
    unsigned char fbuf_out[1024];

    // Open the reading and writing paths.
    std::fstream in(path, std::ios::in | std::ios::binary);
std::fstream out("/encrypted.file", std::ios::out | std::ios::binary);

    // Set up the AES key structure.
    AES_set_encrypt_key(k, 256, &m_encrypt_ctx);

    // Set the IV.
    std::memset(m_iv, rand(), AES_BLOCK_SIZE);

    // Do the actual reading, ecrypting and writing.
    while (!in.eof())
    {
        std::cout << "aes::encrypt_file: Reading..." << std::endl;

        in.read((char *) fbuf_in, 1024);

        unsigned int len = in.gcount();

        std::cout << "aes::encrypt_file: Encrypting..." << std::endl;

AES_cbc_encrypt(fbuf_in, fbuf_out, len, &m_encrypt_ctx, m_iv, AES_ENCRYPT);

        std::cout << "aes::encrypt_file: Writing..." << std::endl;

        out.write((char *)fbuf_out, len);
    }
}

Reply via email to