RSA ๊ฐ์ธํค์ ๋ํ ์คํ ๋ฌธ์๋ PKCS#1 ์ด๋ค. ์ด ๋ฌธ์์ RSA ๊ด๋ จ ํ์ค์ด ์์ธํ ๋์ ์๋ค.
์ฌ๊ธฐ์๋ RSA ๊ฐ์ธํค๋ฅผ ๋ง๋ค๊ธฐ ์ํ OpenSSL ๋ช
๋ น์ด๋ฅผ ์ค๋ช
ํ๋ค.
RSA 2048 ๊ฐ์ธํค ์์ฑ
openssl genrsa -out rsa_private.pem 2048
- RSA ๊ฐ์ธํค ์์ ๊ณต๊ฐํค ์ถ์ด
openssl rsa -in rsa_private.pem -pubout -out rsa_pub.pem
์ด ๋ช
๋ น์ด๋ฅผ ์์ฑ ํ๋ฉด rsa_private.pem ํ์ผ์ RSA ๊ฐ์ธํค ๊ฐ์ด ์ ์ฅ์ด ๋๋ค.
์ด ํ์ผ์ ์์ํ๊ฒ ๊ฐ์ธํค์ ๊ฐ๋ค์ด๋ผ ์ด๋๋ก ์ฌ์ฉํ๊ฒ ๋๋ฉด ๋ณด์์ ๋ฌธ์ ๊ฐ ๋๋ค.
์ฐธ๊ณ ๋ก ๊ฒฐ๊ณผ ๊ฐ์ PEM ํ์์ ๋ฐ์ดํ์ด๋ค.
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEApzAC4RqHg/bswYD62mYy0XvmIoUb2kgnXcfvBd9KrfghR6tu
085pT/3BfH5RUK3zGj0w6ai553TNCEkph0TvTFK1Xo+fPRrDPeCkEE2WnTYd/r7d
YrgdW4JH1yfLyPj1vEtbrp0ifQW78PMT6u/itXV07TxVDdYwU6hevCMMYYa7haGA
z44UKT2e+BVdkHM0ivEgxmqzP5Rp4SZx7xOHXkwBLd9RmAnR0RmdvUHaXYq+D12A
SGqgFab0bQVnBo/b5p5SPJGgB2FrzdC+JiAvHUi37aGr8D5kp6/DUfRzrpKfxiMK
8N5QJWhQKycZXHT8A25kBuvlzvu2a63LW9eQGwIDAQABAoIBACzXmc4auYJRt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uOQ8cmbGTV8kGwDKSdNJGMsI9NhhStdEHG87LeG/ZS76/kI
IIBauHB60VbnVzprErMUnyAPBGHHnjrPMoKOK9Zs0DRA6rmothO/CW5FwpjJ9vlI
vPv7L5JzUMPRVFpfZIsjyRuvhDuI3d6JmMsDr+BW87MIXGrvIeR5
-----END RSA PRIVATE KEY-----
์ฐธ๊ณ ๋ก ----BEGIN PRIVATE KEY----- ์ด๋ ๊ฒ
openssl ๋ฒ์ ์ ๋ฐ๋ผ ์ด๋ ๊ฒ ๋์ค๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ
์ด๊ฒ์ ๋ค๋ฅธ ํ์์ ๊ฐ์ธํค ASN.1 ํฌ๋งท์ผ๋ก ์๊ณ ๋ฆฌ์ฆ ์ ๋ณด๊ฐ ํฌํจ๋ ๊ฒฝ์ฐ์ด๋ค.
์ฐธ๊ณ ๋ก OpenSSL3 ๋ฒ์ ์์ ์์ฑํ BERGIN PRIVATGE KEY ํ์์ ํ๋ฉด ์ฒ๋ผ ๋์จ๋ค.
์ด ํฌ๋งท์ PKCS#8 ํฌ๋งท์ PrivateKeyInfo ํ์์ด๊ณ ๋ด์ฉ์ค์ OCTET STRING ๋ถ๋ถ์ด ๊ฐ์ธํค ์ด๋ค.
OpenSSL 1๋ ๋ฒ์ ์ OCTET STRING ์ ๊ฐ๋ง ๋ง๋ค์ด ์ง๋ค.
RSA ๊ฐ์ธํค์ ๋ํ ASN.1 ๊ตฌ๋ฌธ์ ๋ค์๊ณผ ๊ฐ๋ค.
RSAPrivateKey ::= SEQUENCE {
version Version,
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- p
prime2 INTEGER, -- q
exponent1 INTEGER, -- d mod (p-1)
exponent2 INTEGER, -- d mod (q-1)
coefficient INTEGER, -- (inverse of q) mod p
otherPrimeInfos OtherPrimeInfos OPTIONAL
}
์ด๋ ๊ฒ INTEGER ๊ฐ๋ค์ ๋์ด์ด๋ค.
์ด ํ์ผ์ ๊ทธ๋ฅ BerEditor ๋ก Decoding ํ ํ๋ฉด์ ๋ค์๊ณผ ๊ฐ๋ค.
RSA 2048 ๊ฐ์ธํค ์์ฑ ๋ฐ AES128๋ก ์ํธํ๋ P8 ํ์ ์ ์ฅ
openssl genrsa -aes128 -passout pass:asdf -out rsa_private_enc.pem 2048
๊ฒฐ๊ณผ ํ์ผ๋ก rsa_private_enc.pem ํ์ผ์ ์ด์ด ๋ณด๋ฉด ๋ค์ ์ฒ๋ผ Base64 ์ธ์ฝ๋ฉ ๋ ํ์ผ์ด ์์ฑ๋๋ค.
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIctpVWPVO0Y4CAggA
MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAECBBBXdJMtZpcRwf5vCafwx6jJBIIE
0IMXSg4LYGOIsW6Zu48u2+SvlOcZbQUJ6pkjjhfTFQl4znx5B3AN+9MSFoiJeWeO
Cv6QyOZo2z8BXcFTwLnX/VykO8eYP3irrssgcrJBPmIdOGMVvgm+/YNGeFiD6/4v
rZz1ZHC2PBguQSAMXOgBGizqUDmkGBSuxiD2X2NssLryfPVkyQDN6fs3Pf4hKJwV
VmwNfXm/uFIrecwtzcdjmU751Shw7CmX9Jc1viOB4TzEFrM1trN+isiky8D1nCxs
hacFawJAy3mOGBKfDh1gEYJXbR/mFxSFMIrMJoNfIs0p56PUQ/p06soUpEeDnx1k
3/TQbWGil9UgJ7eNBMG4yC4zb5o7dU3h/TpvM7xIjIwGjujfiyQr+WI5OrRS69ps
9PQf1bV2NOB/FD+wL5p7zmMsLW7DxQ6mpFSZ0GXRxZmZaeFIuSxFVjvMqaLUboSu
+7GDISdrF99ryOB8J/zgluPMePyujoq4LK4GiwYoFX0JFK/MR+CrYUoVTFkvBu31
FESPXKH1Nn2GWAsFI0GpHjKkjbhzJUuovmZYVj58MbipqL3k/rmnU9bB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cilnha3+nWgtDayS44ii
-----END ENCRYPTED PRIVATE KEY-----
์ํธํ๋ ํ์ผ์ ํฌ๋งท์ PKCS#8 ์ ์ ์ ๋์ด์๋ ๋ค์ ASN.1 ํ์์ด๋ค
-- Encrypted private-key information syntax
EncryptedPrivateKeyInfo ::= SEQUENCE {
encryptionAlgorithm AlgorithmIdentifier {{KeyEncryptionAlgorithms}},
encryptedData EncryptedData
}
EncryptedData ::= OCTET STRING
PrivateKeyAlgorithms ALGORITHM-IDENTIFIER ::= {
... -- For local profiles
}
KeyEncryptionAlgorithms ALGORITHM-IDENTIFIER ::= {
... -- For local profiles
}
์ฐธ๊ณ ๋ก BerEditor ์ํธํ๋ P8 ํ์ผ์ Decoding ํ ํ๋ฉด์ด๋ค.
๊ฐ์ธํค ๋ณตํธํ ํ RSA PrivateKey ์ถ์ถ
openssl rsa -in rsa_private_enc.pem -passin pass:asdf -out rsa_private_plain.pem
๊ฐ์ธํค ์์ ๊ณต๊ฐํค ์ถ์ถ
openssl.exe rsa -in rsa_private_plain.pem -out rsa_public.pem -pubout
์ด๋ ๊ฒ ํ๋ฉด ๊ณต๊ฐํค ๊ฐ rsa_public.pem ์ผ๋ก ์ถ์ถ ๋๋ค.
์ถ์ถ๋ rsa_public.pem
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApzAC4RqHg/bswYD62mYy
0XvmIoUb2kgnXcfvBd9KrfghR6tu085pT/3BfH5RUK3zGj0w6ai553TNCEkph0Tv
TFK1Xo+fPRrDPeCkEE2WnTYd/r7dYrgdW4JH1yfLyPj1vEtbrp0ifQW78PMT6u/i
tXV07TxVDdYwU6hevCMMYYa7haGAz44UKT2e+BVdkHM0ivEgxmqzP5Rp4SZx7xOH
XkwBLd9RmAnR0RmdvUHaXYq+D12ASGqgFab0bQVnBo/b5p5SPJGgB2FrzdC+JiAv
HUi37aGr8D5kp6/DUfRzrpKfxiMK8N5QJWhQKycZXHT8A25kBuvlzvu2a63LW9eQ
GwIDAQAB
-----END PUBLIC KEY-----
Pass Phrase ์ ์ํธํ ์๊ณ ๋ฆฌ์ฆ ๋ณ๊ฒฝ
์๊ณ ๋ฆฌ์ฆ: AES128 -> AES256
Pass Phrase: asdf -> hello
openssl rsa -aes256 -in rsa_private_enc.pem -passin pass:asdf -passout pass:hello -out rsa_private_enc2.pem
PKCS8 ํฌ๋งท ๊ฐ์ธํค ์ํธํ
-topk8 : ๊ฒฐ๊ณผ PKCS8 ํ์ผ
-v2 aes128 : PKCS#5 Version 2.0์ฌ์ฉ ๋ฐ AES128 ์ํธํ
openssl pkcs8 -topk8 -v2 aes128 -in rsa_private_plain.pem -out rsa_pri.p8 -passout pass:asdf
PKCS8 ํ์ผ์์ ๊ฐ์ธํค ์ถ์ถ
openssl pkcs8 -in rsa_pri.p8 -out p8_out.pem -passin pass:asdf
์ด๋ ๊ฒ RSA ๊ฐ์ธํค ํฌ๋งท๊ณผ PKCS#8์ ์ํธํ๋ ํ์์ ๋ง๋ค์ด ๋ณด์๋ค.
ECDSA ํ์์ ๊ฐ์ธํค์ PKCS#8 ์ํธํ ํ์๊ณผ Information ํ์์ ๋ํด์๋
๋ค์์ ๊ธฐํ๊ฐ ๋๋ฉด ๋ค๋ฃจ์ด๋ณผ ์์ ์ด๋ค.
'Manual > OpenSSL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[OpenSSL] OCSP ์ TSP ๋ช ๋ น์ด (0) | 2023.04.07 |
---|---|
[OpenSSL] PKCS#12 (PFX) ํ์ผ ๋ง๋ค๊ธฐ ๋ช ๋ น์ด (0) | 2023.04.07 |
[OpenSSL] CMS ( Cryptographic Message Syntax ) ๋ช ๋ น์ด ์ฌ์ฉ๋ฒ (3) | 2023.04.06 |
[OpenSSL] ECDSA ์ฉ Self-Sign ์ธ์ฆ์ ๋ง๋ค๊ธฐ (0) | 2023.04.05 |
[OpenSSL] TLS ์๋ฒ ํ ์คํธ (0) | 2023.04.05 |