decrypt without save

I'm trying to encrypt and decrypt .jpg files.

I have two tools: the first one writes encrypted data to a DVD and the second one decrypts and opens the data from the DVD.

Both tools are working fine as long as a permit the second tool to write somewhere on my harddisc the decrypted file. So the second tool decrypts a file, writes it on my harddisc and opens it in a JPanel.

The problem is that I don't want to save the decrypted file. I want to decrypt and open it at once, without saving it. If this is not possible, then I 'ld like to delete the file as soon as it is shown on the panel. But the delete method of the File class doesn't help me eather.

[683 byte] By [Greeta] at [2007-10-3 3:17:27]
# 1
> The problem is that I don't want to save the> decrypted file. I want to decrypt and open it at> once, without saving it.Of course it is possible but how can we help without seeing your code!
sabre150a at 2007-7-14 21:09:02 > top of Java-index,Security,Cryptography...
# 2

Here comes my decrypt method:

public void decrypt( InputStream aInputStream, OutputStream out ) {

try {

// Bytes read from in will be decrypted

aInputStream = new CipherInputStream(aInputStream, fDecCipher);

// Read in the decrypted bytes and write the cleartext to out

int numRead = 0;

while ((numRead = aInputStream.read(buf)) >= 0) {

out.write(buf, 0, numRead);

}

out.close();

}

catch (java.io.IOException e) {

e.printStackTrace( );

}

}

and here is how I call it:

File outFile = File.createTempFile( "test", ".jpg", new File( "c:/xc_temp" ) );

FileOutputStream outStream = new FileOutputStream( outFile );

encrypter.decrypt( new FileInputStream( "C:/xc_test/ACO/1930/03/19300305/ACO-004-19300305/articles/ACO-004-19300305001.jpg" ), outStream );

openEncryptedFile( outFile.getAbsolutePath() );

outStream.close();

boolean deleted = outFile.delete();

Greeta at 2007-7-14 21:09:02 > top of Java-index,Security,Cryptography...
# 3

Please don't take this wrong but I think you should learn Java. The solution is trivial

ByteArrayOutputStream outStream = new ByteArrayOutputStream();

encrypter.decrypt( new FileInputStream( "C:/xc_test/ACO/1930/03/19300305/ACO-004-19300305/articles/ACO-004-19300305001.jpg" ), outStream );

byte[] decryptedBytes = outStream.toByteArray();

sabre150a at 2007-7-14 21:09:02 > top of Java-index,Security,Cryptography...
# 4

My suggestion is when decrypting file in decrypt() method to save data to ByteArrayOutputStream and then pass bytes from decrypted image as ByteArrayInputStream to openEncryptedFile() method.

ByteArrayOutputStream baos = new ByteArrayOutputStream();

encrypter.decrypt( new FileInputStream( "C:/xc_test/ACO/1930/03/19300305/ACO-004-19300305/articles/ACO-004-19300305001.jpg" ), baos );

openEncryptedFile(new ByteArrayInputStream(baos.toByteArray()));

I suppouse that in openEncryptedFile() method you read image data from file as input stream and than pass it to visual component so changes to your code will be small.

aleksndar.valcheva at 2007-7-14 21:09:02 > top of Java-index,Security,Cryptography...