c++ - Encrypt/Decrypt image file using ElGamal -


i trying encrypt , decrypt image file elgamal in c++. has use elgamal encryption. want save both encrypted file , recovered file. using crypto++ libraries encryption/decryption part. here have far.

autoseededrandompool prng;  elgamal::decryptor decryptor; decryptor.accesskey().generaterandomwithkeysize(prng, 2048); const elgamalkeys::privatekey& privatekey = decryptor.accesskey();  elgamal::encryptor encryptor(decryptor); const publickey& publickey = encryptor.accesskey();  string ofilename = "test.bmp"; string efilename = "test.enc"; string rfilename = "test-recovered.bmp";  filesource fs1(ofilename.c_str(), true, encryptor.createencryptionfilter(encryptor.encrypt, new filesink(efilename.c_str())));  filesource fs2(efilename.c_str(), true, decryptor.createdecryptionfilter(decryptor.decrypt, new filesink(rfilename.c_str()))); 

i stuck @ encryption , decryption part. appreciated!

your problem you're trying encrypt arbitrarily large data using asymmetric cryptosystem. asymmetric cryptosystems cannot encrypt data length larger size of modulus. (see why doesn't implementation of elgamal work long text strings?)

the typical workaround limitation perform symmetric transformation input using standard symmetric algorithm (e.g. aes) , encrypt symmetric key using asymmetric public key. decryption reverses operation first decrypting symmetric key , use symmetric key decrypt encrypted content.

crypto++ elgamal objects offer symmetricencrypt , symmetricdecrypt. functions encrypt , decrypt arbitrary length text under symmertic key, , encrypt symmetric key under elgamal public key. (see crypto++ wiki - elgamal)


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -