Create an encryption state structure using the encryption context.
void mco_crypt_init_state(mco_crypt_ctx_t const* crypt_ctx, mco_crypt_state_t* state);
crypt_ctx | The address of the encryption context to initialize |
state | The address of the encryption state structure |
This function creates an encryption state structure using the pre-initialized encryption context. This state, used by function mco_crypt_stream(), reflects the encryption process at current location of a stream.
void | No value returned |
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);