# mco_crypt_init_state
RT

Create an encryption state structure using the encryption context.

### For an overview see page Encryption C API

### Prototype

        void mco_crypt_init_state(mco_crypt_ctx_t const* crypt_ctx, mco_crypt_state_t* state);

### Arguments

crypt_ctx | The address of the encryption context to initialize
state | The address of the encryption state structure

### Description

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.

### Return Codes

void | No value returned

### Example

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);

### Files

Header file:
mco.h
Source file:
mcocryptaes.c
Library:
libmcocryptaes.a
Header file:
mco.h
Source file:
mcocryptstub.c
Library:
libmcocryptstub.a