언어 설정

Menu
Sites
Language
Encrypting image files .jpg

I am trying to encrypt a image file which is of jpg format, i am successfull in encrypting the image & after decrypting  if i try to open the image file it is giving 
Error :Error interpreting JPEG image file (Not a JPEG file: starts with 0xef 0xbf)
any one please help me in solving the above issue my sample code is as shown below

File file;
file.Construct(filepath,"a+");
String strBuf;
file.Read(strBuf);
ByteBuffer *ebuf = dm.encrypt(strBuf,"e",iv);
ByteBuffer *dbuf = dm.decrypt(*ebuf,"e",iv);

File file1;//dest file after decryption

file1.Construct(Tizen::System::Environment::GetExternalStoragePath()+L"MyImage"+L"/"+L"h.jpg","a+");

file1.Write(*dbuf);

 

Responses

6 댓글
Alex Ashirov

Hi,

It isn't clear enough what class is object dm? But anyway did you compare strBuf and dbuf before writing the dbuf to file?

harish kumar kavali

Hi alex

here dm is my class object dm.encrypt() encrypts the bytebuffer data dm.decrypt() decrypts the bytebuffer data
if had checked , both strBuf and dBuf contains same data

  

Alex Ashirov

If they (strBuf and dBuf) really contain the same data then this means that encryption/decryption is not a reason of the issue. If so, could you please try something like this:

File file;
file.Construct(filepath,"a+");
String strBuf;
file.Read(strBuf);
File file1;//dest file after decryption

file1.Construct(Tizen::System::Environment::GetExternalStoragePath()+L"MyImage"+L"/"+L"h.jpg","a+");

file1.Write(strBuf);

Does this work correct?

harish kumar kavali

Hi Alex
even this also not working , may be error in reading data from to byte buffer is there any other methods to follow

Alex Ashirov

Please try to open file1 with “w+” mode instead of “a+”.

harish kumar kavali

Hi alex
thank you so much , my problem solved by passing encoded bytebuffer as input to the encryption function
1.i had converted the byte buffer to string 
2.converted the string to encoded string 
3.then converted the encoded string to bytebuffer
4.passed the bytebuffer as input to the encryption function                                                                                                                                                                             5.write the bytebuffer to image file in w+mode

and at the time of decryption i decrypted the data & then decoded &then created a image file.