Encrypts or decrypts a stream of data using the encryption context and state.
void mco_crypt_stream(mco_crypt_ctx_t const* crypt_ctx,
mco_crypt_state_t* state,
uint1* buf,
uint4 size);
crypt_ctx
state
buf
size
buf.This function encrypts or decrypts a data buffer buf of size size to be placed into or retrieved from a stream.
Unlike the block-based function mco_crypt_block(), this function assumes an arbitrary buffer
size that is the usual usage pattern for stream-based operations.
void
The following code snippet demonstrates encrypting / decrypting an external file:
/* Code sample for stream-based encryption */
FILE *fin, *fout;
char buff[100];
const int buff_size = sizeof(buff);
const char *cipher = "my cipher key";
mco_crypt_ctx_t crypt_ctx;
mco_crypt_state_t crypt_state;
size_t n;
mco_crypt_init_ctx(&crypt_ctx, cipher);
mco_crypt_init_state(&crypt_ctx, &crypt_state);
fin = fopen("unencrypted.file", "rb");
fout = fopen("encrypted.file", "wb");
do
{
n = fread(buff, buff_size, 1, fin);
mco_crypt_stream(&crypt_ctx, &crypt_state, buff, (uint4)n);
fwrite(buff, n, 1, fout);
} while (n == buff_size);
fclose(fin);
fclose(fout);