Here are is an example for Visual C++ that demonstrates encryption from file to memory in a single pass. It shows how to use the Rijndael algorithm.
VC++ |
Copy Code |
// This code uses the #import directive.
// Put the following line at the beginning of your module #import "XCEEDCRY.DLL" no_namespace named_guids
CoInitialize( NULL );
try { IXceedEncryptionPtr piEnc;
piEnc.CreateInstance( CLSID_XceedEncryption ); piEnc->License( _bstr_t( L"your license key ) );
IXceedRijndaelEncryptionMethodPtr piRijndael;
piRijndael.CreateInstance( CLSID_XceedRijndaelEncryptionMethod ); piRijndael->SetSecretKeyFromPassPhrase( "This is a weak pass phrase!", 128 );
piEnc-> EncryptionMethod = IXceedEncryptDataPtr( piRijndael );
BYTE* pcData = NULL; DWORD dwBytesRead; DWORD dwDataSize;
piEnc->ReadFile( "c:\\temp\\source.txt", 0, 0, efpEncrypt, TRUE, & dwBytesRead, &pcData, &dwDataSize );
MessageBox( NULL, "File encrypted successfully to memory", "Encryption result", MB_OK );
CoTaskMemFree( pcData ); } catch( const _com_error& xErr ) { char szMsg[50]; wsprintf( szMsg, "Error %08x\n", xErr.Error() ); MessageBox( NULL, szMsg, "Error", MB_OK ); } catch( ... ) { MessageBox( NULL, "Unknown error", "Error", MB_OK ); }
CoUninitialize(); |