--Apple-Mail-3--621267439
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit

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:ut |
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);
}
}
--Apple-Mail-3--621267439
Content-Type: text/html;
charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

-webkit-line-break: after-white-space; ">
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; font-size: 11px; "> class=3D"Apple-style-span" color=3D"#00000000"> class=3D"Apple-style-span" style=3D"background-color: =
transparent;">The encrypted.file is exactly as the =
original.
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; font-size: 11px; ">
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
font-size: 11px; ">Thanks in advance,
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 10px/normal Monaco; font-size: 11px; =
">julian
margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
10px/normal Monaco; "> color=3D"#AA0D91">
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; "> #aa0d91">void #3f6e74">aes::encrypt_file( #aa0d91">const char * key, =
const #aa0d91">char * path, 
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; color: rgb(170, 13, 145); "> style=3D"color: #000000">    unsigned style=3D"color: #000000"> char * =
buf #000000"> /*[in|out]*/ style=3D"color: #000000">)
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; ">{
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "> style=3D"color: #000000">    // ...
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
">    unsigned style=3D"color: #aa0d91">char fbuf_in[ class=3D"Apple-style-span" color=3D"#1C00CF">1024];
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
">    unsigned style=3D"color: #aa0d91">char fbuf_out[ class=3D"Apple-style-span" color=3D"#1C00CF">1024];
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
min-height: 14px; ">
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "> style=3D"color: #000000">    // Open the reading and =
writing paths.
margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
10px/normal Monaco; ">    #3f6e74">std::fstream style=3D"color: #2e0d6e">in(path, #3f6e74">std::ios::in | =
std:: #5c2699">ios:: #5c2699">binary);
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; ">    #3f6e74">std::fstream style=3D"color: #2e0d6e">out( #c41a16">"/encrypted.file", #3f6e74">std::ios:ut | =
std:: #5c2699">ios:: #5c2699">binary);
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; min-height: 14px; ">
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: =
rgb(0, 116, 0); ">    // =
Set up the AES key structure.
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; ">    #2e0d6e">AES_set_encrypt_key(k, #1c00cf">256, &m_encrypt_ctx);

0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px">   =
 

0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "> style=3D"color: #000000">    // Set the IV.
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
">    std:: style=3D"color: #2e0d6e">memset(m_iv, #2e0d6e">rand(), #643820">AES_BLOCK_SIZE);

0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px">   =
 

0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "> style=3D"color: #000000">    // Do the actual reading, =
ecrypting and writing.
0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
10px/normal Monaco; ">    #aa0d91">while (!in. #2e0d6e">eof())
0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
10px/normal Monaco; ">    {
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 10px/normal Monaco; color: rgb(196, 26, 22); =
">        =
std #000000">::cout style=3D"color: #000000"> << "aes::encrypt_file: =
Reading..." << style=3D"color: #3f6e74">std #000000">::endl;

0.0px; font: 10.0px Monaco; min-height: 14.0px">     =
   

style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
">        in. #2e0d6e">read((char *) =
fbuf_in, color=3D"#1C00CF">1024);
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; min-height: 14px; ">
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
">        #aa0d91">unsigned int len =3D=
in.gcount();

style=3D"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; =
min-height: 14.0px">        
class=3D"webkit-block-placeholder">

margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 10px/normal Monaco; color: rgb(196, 26, 22); "> style=3D"color: #000000">        style=3D"color: #3f6e74">std #000000">::cout style=3D"color: #000000"> << "aes::encrypt_file: =
Encrypting..." << style=3D"color: #3f6e74">std #000000">::endl;

0.0px; font: 10.0px Monaco; min-height: 14.0px">     =
   

style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
">        #2e0d6e">AES_cbc_encrypt(fbuf_in, fbuf_out, len, =
&m_encrypt_ctx, m_iv, #643820">AES_ENCRYPT);

0.0px; font: 10.0px Monaco; min-height: 14.0px">     =
   

style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: =
rgb(196, 26, 22); ">      =
 
std style=3D"color: #000000">:: #5c2699">cout << =
"aes::encrypt_file: Writing..." =
<<
std style=3D"color: #000000">::endl;

0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px">   =
     

style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 10px/normal Monaco; =
">        out. #2e0d6e">write((char =
*)fbuf_out, len);
margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
10px/normal Monaco; ">    }
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 10px/normal Monaco; ">}
=

--Apple-Mail-3--621267439--
__________________________________________________ ____________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager majordomo@openssl.org