Hi Look into help (on-line). There is an example how use crypt functions. Anyway, some time or other I made two a very simple programs. One for encrypt and one for decrypt. I hope this will be useful for you. Just change CBC_Mode<AES> to CBC_Mode<Serpent>, other things with 'AES' keyword and also add a new #include.
Regards ----- /* ENCRYPTING FILES - SZYFROWANIE PLIKOW - Dariusz Chilimoniuk http://www.elwizard.com 18-VII-2003 - Program demonstruje uzycie klas FileSource, FileSink, - StreamTransformationFilter, CBC_Mode<T>, SHA256, ArraySink, - StringSource, HashFilter, AutoSeededRandomPool - do budowy programu szyfrujacego */ //#include "stdafx.h" #include "filters.h" #include "files.h" #include "sha.h" #include "modes.h" #include "aes.h" #include "mars.h" #include "osrng.h" #include <iostream> #include <cstring> USING_NAMESPACE(CryptoPP) USING_NAMESPACE(std) int main() { byte pass[ SHA256::DIGESTSIZE ];// digest of password byte iv[ AES::BLOCKSIZE ];// Initial Vector (IV) byte block[ AES::BLOCKSIZE ];// auxliary buffer AutoSeededRandomPool *rng; rng = new AutoSeededRandomPool;// random number generator string file, password; cout << "*** ENCRYPT ***\nType file name: " << endl; getline(cin, file); cout << "Enter password: "; getline(cin, password);// of corse it is not secure solution // digest password delete new StringSource( password, true, new HashFilter(*(new SHA256), new ArraySink(pass,SHA256::DIGESTSIZE)) ); // random Initial Vector rng->GenerateBlock(iv, AES::BLOCKSIZE); // create object for encrypting StreamTransformationFilter *encryptor; encryptor = new StreamTransformationFilter( *new CBC_Mode<AES>::Encryption(pass, AES::DEFAULT_KEYLENGTH, iv), new FileSink( (file+".encrypt").c_str() ) ); //HEADER OF ENCRYPTED FILE: // 3 special blocks // (It works only with CBC mode) // // Let explain a little: // Encrypt process: // (a) get random IV; // (b) encrypt 3 special blocks: // - block1 and block2 are filled random data, // - block3 contain the same data what are in block2 // // Decrypt process: // (a) decrypt first three blocks (IV is unimportant); // (b) if block2 is equal with block3 then password is correct and // continue decrypting rng->GenerateBlock(block, AES::BLOCKSIZE); encryptor->Put(block, AES::BLOCKSIZE);// block1 rng->GenerateBlock(block, AES::BLOCKSIZE); encryptor->Put(block, AES::BLOCKSIZE);// block2 encryptor->Put(block, AES::BLOCKSIZE);// block3 delete rng; // "bind" a file and encrypt one delete new FileSource(file.c_str(), true, encryptor); cout << "Done !" << endl; return 0; } /* DECRYPTING FILE - DESZYFROWANIE PLIKOW - Dariusz Chilimoniuk http://www.elwizard.com 18-VII-2003 */ //#include "stdafx.h" #include "filters.h" #include "files.h" #include "sha.h" #include "modes.h" #include "aes.h" #include <iostream> #include <cstring> USING_NAMESPACE(CryptoPP) USING_NAMESPACE(std) int main() { byte pass[ SHA256::DIGESTSIZE ]; byte iv[ AES::BLOCKSIZE ]; byte head_file[ 3 * AES::BLOCKSIZE ]; byte head_file_dec[ 3 * AES::BLOCKSIZE ]; memset(iv, 0, AES::BLOCKSIZE ); string file, file_out, password; cout << "*** DECRYPTING ***\nType file name: " << endl; getline(cin, file); cout << "Enter password: "; getline(cin, password); FileSource *source; source = new FileSource(file.c_str(), false); delete new StringSource( password, true, new HashFilter(*(new SHA256), new ArraySink(pass, SHA256::DIGESTSIZE)) ); CBC_Mode<AES>::Decryption *decryption; decryption = new CBC_Mode<AES>::Decryption(pass, AES::DEFAULT_KEYLENGTH, iv); // checking password // get and encrypt 3 blocks source->Pump(3 * AES::BLOCKSIZE); source->Get(head_file, 3 * AES::BLOCKSIZE); decryption->ProcessBlocks(head_file_dec, head_file, 3); // compare block2 and block3 if(0 != memcmp( &head_file_dec[AES::BLOCKSIZE], &head_file_dec[2*AES::BLOCKSIZE], AES::BLOCKSIZE)) { cout << "Bad password !" << endl; return 0; } // password is correct so continue cout << "Type output file name:" << endl; getline(cin, file_out); // "bind" decryptor to output file source->Attach( new StreamTransformationFilter(*decryption, new FileSink(file_out.c_str()) ) ); // push the rest data source->PumpAll(); cout << "Done !" << endl; return 0; } ---- 2005/12/30, changsengua (sent by Nabble.com) <[EMAIL PROTECTED]>: > I am a newbie to use crypto5.0 and i have a project just want to encrypt and > decrypt a file ,for example like .doc, .txt and so on, I face a problem is i > cannot use the Serpent function to encrypt the whole file, can anyone give > me the tips to do the encrypt and decrypt the file, the DES_EDE2 can > function, but i don't know how to change it to serpent, anyone can help me? > ________________________________ > Sent from the Crypto++ forum at Nabble.com: > Problem with Serpent Encrypt and Decrypt a File -- Dariusz Chilimoniuk +48 504 228 158
