LoginSignup
9
15

More than 3 years have passed since last update.

.pkcs12ファイル → .pemファイル変換

Last updated at Posted at 2020-05-26

pkcs12とは

Public Key Cryptography Standard#12。
公開鍵証明書および秘密鍵をパスワードベースの対象鍵で保護し、安全に保存または転送するために使用されるファイル形式

pemとは

任意の証明書、鍵をbase64エンコードしてBEGIN/END行で挟んで繋げたテキストファイル

.pkcs12ファイル → .pemファイルに変換 (暗号化解除)

openssl pkcs12 -in file.p12 -out file.pem -nodes

「-nodes」オプションを指定すると、秘密鍵にパスフレーズを付けた暗号化が行われない。
使用するたびにパスワード入力求められないように。

PKCSから証明書、鍵の抜き出し

・CA証明書だけ抜きだす 
$ openssl pkcs12 -in file.p12 -out ca.pem -cacerts -nokeys

・鍵と証明書を抜き出す
$ openssl pkcs12 -in file.p12 -out cert.pem -clcerts

・証明書だけ抜き出す
$ openssl pkcs12 -in file.p12 -out cert.pem -clcerts -nokeys

・鍵だけ抜き出す
$ openssl pkcs12 -in file.p12 -out key.pem -nocerts

・鍵だけ抜き出す(パスフレーズ解除)
$ openssl pkcs12 -in file.p12 -out key.nopass.pem -nocerts -nodes

おまけ

curlでクライアント証明書と秘密鍵を指定してリクエスト

curl --key key.nopass.pem --cert cert.pem {URL}

IAM証明書アップロード

aws iam upload-server-certificate --server-certificate-name ExampleCertificate --certificate-body file://cert.pem --private-key file://key.nopass.pem
aws iam list-server-certificates

参考サイト

opensslとcurlでクライアント証明書を使ってHTTPS接続する
PEMファイルとは何ですか?

9
15
0

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
9
15