LoginSignup
3

More than 5 years have passed since last update.

[java]プログラムからPKCS12ファイルの生成

Posted at

PKCS12ファイルはjavaプログラムでは生成できないので外部プロセスのopensslを利用します。
プロセスを実行した後パスフレーズを求められます。

String processStr = "openssl pkcs12 -export -inkey greenwich.key -in greenwich.crt -out greenwich.p12";
Process process = r.exec(processStr);

Thread.sleep(1000); // 1秒待ってから処理しよう

PrintStream out = new PrintStream(process.getOutputStream()); 

String password = "greenwich"; // パスフレーズ
out.println(password); 
out.flush();

Thread.sleep(1000); // 1秒待ってから処理しよう
out.println(password); // 再入力パスフレーズ
out.flush();

out.close();

boolean ret = process.waitFor(10, TimeUnit.MINUTES);
process.destroy();

※linux環境でのコマンド
こんな感じでパスフレーズを入力し証明書と秘密鍵からPKCS12ファイルを生成します。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3