1

APIを介してPKCS12キーストアを生成しましたが、プロセスの戻り値はKeyStoreオブジェクトです。クライアントが要求を送信するときにダウンロードするために、ブラウザに直接送信する必要があります。

どうやってやるの?

私はjavaとjboss5ASを使用しています。

4

2 に答える 2

2

KeyStore#store()に書き出すために使用できますOutputStream

keyStore.store(outputStream, password);

基本的にはそれだけです。はOutputStreamHTTP応答の1つである可能性があります。この行を統合する必要があるJSFでファイルのダウンロードを提供する方法の一般的なキックオフの例については、次の回答に進んでください。JSFバッキングBeanからファイルのダウンロードを提供する方法は?のコンテンツタイプを使用しますapplication/x-pkcs12

于 2013-03-27T02:07:12.777 に答える
1

コードは次のとおりです。

public void cadastrar () throws Exception
{       
    byte[] encodedKeyStore = controlador.cadastrar(certificadoModel);

    java.security.KeyStore keyStore = java.security.KeyStore.getInstance("PKCS12");
    keyStore.load(new ByteArrayInputStream(encodedKeyStore), certificadoModel.getPassword().toCharArray());

    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();

    ec.responseReset(); 
    ec.setResponseContentType("application/x-pkcs12"); 
    //ec.setResponseContentLength(contentLength); 
    ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + certificadoModel.getUsername() + ".p12" + "\""); 

    OutputStream output = ec.getResponseOutputStream();
    keyStore.store(output, certificadoModel.getPassword().toCharArray());

    fc.responseComplete(); 
}
于 2013-03-27T13:51:34.067 に答える