Load an Encrypted .red File

Here is how to know if a file is encrypted or not:

// iresmgr is a pointer to the RED::IResourceManager interface.
RED::Object* red_file = RED::Factory::CreateInstance( CID_REDFile );
RED::IREDFile* ifile = red_file->As< RED::IREDFile >();

RED::StreamingPolicy policy;
RED::FileHeader fheader;
RED::FileInfo finfo;
RED::Vector< unsigned int > context;

RED_RC rc = ifile->Load( "./my_file.red", iresmgr->GetState(), policy, fheader, finfo, context );
if( rc == RED_OK )
{
    // File is not encrypted.
}
else if( rc == RED_ENCRYPTED_FILE )
{
    // File is encrypte: prompt the user for the right encryption key.
}
else
{
    // An error occured: look at rc to identify the issue.
}

The key is not stored into the encrypted file and people wanting to read the file must have previously received the key through another mean.

// iresmgr is a pointer to the RED::IResourceManager interface.
RED::Object* red_file = RED::Factory::CreateInstance( CID_REDFile );
RED::IREDFile* ifile = red_file->As< RED::IREDFile >();

RED::StreamingPolicy policy;
RED::FileHeader fheader;
RED::FileInfo finfo;
RED::Vector< unsigned int > context;

RED::String encryption_key = "encryption key used to encrypt the source file";

// Loading and decrypting are done simultaneously by the next call.
RC_TEST( ifile->Load( "./my_file.red", iresmgr->GetState(), policy, fheader, finfo, context, 0, encryption_key ) );