0

暗号化された形式でファイルをアップロードするために使用される署名付きアプレットを開発しました。このアプレットは正常に動作している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>
4

1 に答える 1

3

最も簡単な方法は、HttpClientApacheCommonsライブラリを使用することです。アプレットで次のようなことを行う必要があります。

    public void sendFile throws IOException {
        HttpClient client = new HttpClient();
        PostMethod postMethod = new PostMethod("http://yourserverip:8080/yourServlet");

        File f = new File(destFileName);
       
        postMethod.setRequestBody(new FileInputStream(f));
        postMethod.setRequestHeader("Content-type",
            "text/xml; charset=ISO-8859-1");

        client.executeMethod(postMethod);
        postMethod.releaseConnection();
    }

これにより、ファイルを取得できるサーブレットdoPost()メソッドがトリガーされます。あなたが言ったように、あなたのアプレットはこれを行うことを許可されるように署名されるべきです。

于 2012-07-30T13:37:38.690 に答える