APIを介してPKCS12キーストアを生成しましたが、プロセスの戻り値はKeyStoreオブジェクトです。クライアントが要求を送信するときにダウンロードするために、ブラウザに直接送信する必要があります。
どうやってやるの?
私はjavaとjboss5ASを使用しています。
KeyStore#store()
に書き出すために使用できますOutputStream
。
keyStore.store(outputStream, password);
基本的にはそれだけです。はOutputStream
HTTP応答の1つである可能性があります。この行を統合する必要があるJSFでファイルのダウンロードを提供する方法の一般的なキックオフの例については、次の回答に進んでください。JSFバッキングBeanからファイルのダウンロードを提供する方法は?のコンテンツタイプを使用しますapplication/x-pkcs12
。
コードは次のとおりです。
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();
}