jpeg - Image Encryption -
i doing image steganography , if type message greater 3 chars encrypt there exception quantization table 0x01 not defined , message less 3 char got encrypted image needed .i think due jpeg format (i think while injecting bits in image byte array hv destroyed property , attributes of image ).help me sure related metadata don`t know it.
i adding code doing
creating_image() { file f=new file(file.getparent()+"/encrypt.jpg"); if(file==null) { joptionpane.showmessagedialog(rootpane, "file null ho gyi encrypt mein"); } try{ fileinputstream imageinfile = new fileinputstream(file); byte imagedata[] = new byte[(int) file.length()]; imageinfile.read(imagedata); // converting image byte array base64 string string imagedatastring = base64.encode(imagedata); // converting base64 string image byte array pixels = base64.decode(imagedatastring); // write image byte array file system imageinfile.close(); } catch(exception as) { joptionpane.showmessagedialog(rootpane,"please first select image"); } string msg=jtextarea1.gettext(); byte[] bmsg=msg.getbytes(); string as=base64.encode(bmsg); bmsg=base64.decode(as); int len=msg.length(); byte[] blen=inttobyte(len); string sd=base64.encode(blen); blen=base64.decode(sd); pixels=encode(pixels,blen,32); pixels=encode(pixels,bmsg,64); try{ // converting image byte array base64 string string imagedatastring = base64.encode(pixels); // converting base64 string image byte array pixels = base64.decode(imagedatastring); inputstream baisdata = new bytearrayinputstream(pixels,0,pixels.length); image= imageio.read(baisdata); if(image == null) { system.out.println("imag empty"); } imageio.write(image, "jpg", f); } catch(exception s) { system.out.println(s.getmessage()); } }
and thats encode fxn looks like
byte[] encode(byte [] old,byte[] add,int offset) { try{ if(add.length+offset>old.length) { joptionpane.showmessagedialog(rootpane, "file short"); } } catch(exception d) { joptionpane.showmessagedialog(rootpane, d.getlocalizedmessage()); } byte no; for(int i=0;i<add.length;i++) { no=add[i]; for(int bit=7;bit>=0;bit--,++offset) { int b=(no>>bit)&1; old[offset]=(byte)((old[offset]&0xfe)|b); } } return old; }
you correct in have disturbed file structure. jpeg format contains highly compressed data point none of bytes represent pixel values directly. in fact, jpeg doesn't store pixel values, dct coefficients of pixel blocks.
your method of reading raw bytes of file work format bmp, pixels directly stored in file. however, you'd still have skip first few bytes (header), contain information width , height of image, number of colour planes , bits per pixel.
if want embed message modifying least significant bits of pixels, have load actual pixels in byte array. can modify pixels encode()
method. save data file, convert byte array buffferedimage object , use imageio.write()
. however, must use format not involve lossy compression, because can distort pixel values, thereby destroying message. losslessly compressed (or uncompressed) file formats include bmp , png, while jpeg lossy.
if still want jpeg steganography, process bit more involving, this answer pretty covers need do. briefly, want borrow source code of jpeg encoder because writing 1 complex , requires intricate understanding of whole format. encoder convert pixels bunch of different numbers (lossy step) , store them compactly file. steganography algorithm should injected between these 2 steps, can modify numbers before saving them file.
Comments
Post a Comment