Hello, > The encrypted.file is exactly as the original. If length of your file is multiple of 16 then you will got this behavior. AES_encrypt_cbc() function does not add additional padding block in this case. > 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); I'm not sure how this is going to work. rand() returns integer between 0 and RAND_MAX. m_iv should be 16-byte table (vector) and you should initialize every 16 bytes in this table. > // 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); > } > }
Best regards, -- Marek Marcola <[EMAIL PROTECTED]> ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]