I have developed an signed applet that is used to upload a file in encrypted form.
This applet I am calling from jsp which is working fine, but my issue is :
Can I call that applet from jsp in such way that will return encrypted file in jsp and I pass that file to server side?
And Can I create multipart file in applet or jsp for that encrypted file and send it to server?
My running Applet looks like:
public static void encryptDecryptFile(String srcFileName,
String destFileName, Key key, int cipherMode) throws Exception {
OutputStream outputWriter = null;
InputStream inputReader = null;
try {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
byte[] buf = cipherMode == Cipher.ENCRYPT_MODE ? new byte[100]
: new byte[128];
int bufl;
cipher.init(cipherMode, key);
outputWriter = new FileOutputStream(destFileName);
inputReader = new FileInputStream(srcFileName);
while ((bufl = inputReader.read(buf)) != -1) {
byte[] encText = null;
if (cipherMode == Cipher.ENCRYPT_MODE)
encText = encrypt(copyBytes(buf, bufl), (PublicKey) key);
else
encText = decrypt(copyBytes(buf, bufl), (PrivateKey) key);
outputWriter.write(encText);
}
} catch (Exception e) {e.printStackTrace();
throw e;
} finally {
try {
if (outputWriter != null)
outputWriter.close();
if (inputReader != null)
inputReader.close();
} catch (Exception e) {
}
}
}
My Calling jsp looks like :
<applet id="upload" name="upload" code="TestApplet.class" archive="Encrypt.jar" width="360" height="350"></applet>
The easiest way would be using HttpClient Apache Commons library. You will have to do something like this in your applet:
This will trigger your servlet doPost() method where you can retrieve the file. As you said, your applet should be signed to be allowed to do this.