i am working on my final year project in JAVA
1)hiding text in a image
2)image in a image
3)text in a audio file (WAVE)
i have successfully completed 1) and 2) and have attached the source code if anybody may need it. i am having trouble in the 3rd one i.e hiding data in a audio file . I create a audioinputstream out of a wave file and read it's data into a byte array but many things are not clear,while reading i'm guessing the 1st 44 bytes are the header bytes?(since the file is of WAVE format) or the header is not copied at all. The Problem is .... at the time of decoding again i have to read the data from the newly created audio file in a byte array. And i'm not able to locate the bytes where i have hidden data.
Can anybody tell me what exactly happens when we read data into a byte array from a audioinputstream , i mean what actually gets read into the byte array?
File fileIn = new File("C:\\Users\\Rahul\\Desktop\\pro\\Don't Stay.wav");
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(fileIn);
int avail= audioInputStream.available();
System.out.println("bytes available " +avail);
System.out.println(audioInputStream.markSupported());
int bytesPerFrame =
audioInputStream.getFormat().getFrameSize();
// Set an arbitrary buffer size of 1024 frames.
int numBytes = 1024 * bytesPerFrame;
byte[] audioBytes = new byte[numBytes];
audioInputStream.read(audioBytes);
byte btext[]=Stego_text("good morning!");
byte bcoded[]=steg.encoding(audioBytes,btext,0);
byte[] stg= a.decode_text(audioBytes);
String obtain= new String(stg);
System.out.println(">>>"+ obtain); //the hidden message gets successfully displayed here
try {
//
AudioSystem.write(audioInputStream, Type.WAVE, new File("C:\\Users\\Rahul\\Desktop\\pro\\Don't Stay_restored.wav"));
} catch (Exception e) {
e.printStackTrace();
}
byte[] audioBytesNew = new byte[numBytes];
audioInputStream.read(audioBytesNew);
byte[] stg1= a.decode_text(audioBytesNew);
String obtain1= new String(stg1);
System.out.println(">>>"+ obtain1); //the hidden message does not get displayed
if i decode the byte array just after editing , then it works fine and displays the hidden message, but after again creating a byte array and reading into it audioinputsream data and then decoding that byte array .. it does not work. i wonder WHY? please help me.
The first 44 bytes are indeed the header of the WAV (see https://ccrma.stanford.edu/courses/422/projects/WaveFormat/)
If you open the file in an HEX editor, you'll see what it looks like (http://imgur.com/iliA40R)
If you compare the data in the file and the data read by your InputStream, it matches.
You should close and re-open your stream if you need to read the file again. If you can mark the file, you could mark it before reading, and call reset() after the first read is done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With