暗号化された形式でファイルをアップロードするために使用される署名付きアプレットを開発しました。このアプレットは正常に動作しているjspから呼び出していますが、私の問題は次のとおりです。jspで暗号化されたファイルを返し、そのファイルをサーバー側に渡すような方法でjspからそのアプレットを呼び出すことはできますか? また、その暗号化されたファイルに対してアプレットまたは jsp でマルチパート ファイルを作成し、サーバーに送信できますか?
私の実行中のアプレットは次のようになります。
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) {
}
}
}
私のCalling jspは次のようになります:
<applet id="upload" name="upload" code="TestApplet.class" archive="Encrypt.jar" width="360" height="350"></applet>