web-dev-qa-db-ja.com

暗号化された秘密鍵からRSA秘密鍵

私は暗号化された秘密鍵(たとえば、servenc.key)を以下の形式で持っています:

-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIC2TBTBgkqhkiG9w0BBQ0wRjAlBgkqhkiG9w0BBQwwGAQSIFFvMaBFyBvqqhY6
yTV2fMVVAgIUczAdBglghkgBZQMEASoEEGRetyFtHhnJ7TZTM2qolWkEggKAFg/h
GERtM1loEd+u8VAtLwTzBiXE5pmRpp/hX/1HrbBnzFjAsNtWlEtzpSuxuCoXtMst
uKRB8qveHlfTQPzopkRZtljfOkD1DhdJz8BXSZrFmVkMrUq6m4Y/rnqTqI5JmtmQ
qAXTBbl7u8TwMnqIaoSInEHnc+aiFT3KJuIq6PZy2rGKWGW2WB/OML2gANvHBI9n
gyOo4VZHNsR6VBbCRJErUFhF5Wk2/YJD9ejnvXH6pJFqZYvnCFjkSlR+4MdCHBSo
Ld0IoFjQ6X1uLLglFf/rQGKEQruLjTKmz6oe8nZIzrOoLmArir0DGTakEt0K6mha
0M5s9zNkdMd7XRns0uvmYHzbpNVWpUP5YUmf1BJLjTHex51Msjoz6v6ixinel852
5lS2wtVwXp8MXG9iofvMEDocmvn60vuksmgwxMccRWX2zAt8ixFefzIjM0KzPRpt
ByJP0B733u+DI0Y5bsiJVAxl7Gr8Io5k6Uk0nZziVK8+vDXLF2BNetp4kRM/XBaM
N/DcosGiAxOeJqSA45ethV8cHGZVuNOsCXSVomVoKIxgWhkyBzXv9sIbRSSGWfJQ
edWEV9t4RTCgIu+622JZFzw1PbWtEu4R38v0JZQN3zxkYPC7nFIfmx9unUWucoup
ZYbvlzjyNZ6VI8jDvvqy+XmaY+FZcSgPTGCz/4KArxJuSvE8gJULUS7Y7JCuDjjL
h04pYsl8WMA3UH2/CxiFv75vXZI0q2HKUnNNawrQG83zPfBiVrDQARifCkPmzsCd
tHd8A/agDAeg9rmat6PRC4d0to6pUg7v5ZR9VZkRWMJiPMtuH4fh/2L/ys/9EihG
CZJe6XTZkgFAp9gzGg==
-----END ENCRYPTED PRIVATE KEY-----

キーの上のTHはPKCS#8形式です。

RSA秘密鍵PKCS#1形式に変換したい

私が使用するコマンドは次のとおりです。

openssl rsa -in servenc.key -out serv.key

私が得る出力は以下の形式です:

-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDymMsf+68EERSkXO7lwucBa5Ibw+74z+dL/yYWsHxsl+j9E3ZK
5hQ9riiDxscTd+Jm6aqYF5Dobsk+VWoz7Ma+4iLvHiLevefRxlq7Fpe70vRZeNR5
Z+9cLaak4C4/FYrUoOrMjfHxX0Ihmc5M+Tjy4brxpktCTRRm73CyMxT7twIDAQAB
AoGBAOXc8rJWVqmiyY1HZTEdMKb+1w0p5Leqvr0agGuFRA/dDG0nULF9OfaLm2Xp
Jd4DfOkIRJUh1zL1Lge7BQs4McL529nbKirlstUDvR+dRYoyhCNCnVNqKgU/P+Ed
1wEOhVxOLKfcv847huDzzBU7ZL8E3QEQUd9t3CLj3Ov/c2C5AkEA+ks6fX0GXWht
D6IHW+XBEW4txkfm2WWI64RG8Y0avjg9P1vhw/APlCuZPRmsXQ6S9/wKJt/iy0ah
eJVJ3f1/3QJBAPggpLsU7H/0PKCmC8HUrnWG7ANIiZJYib5LJWAnCzpxNNMNmY5Z
0Ak18/ia4bloNz/g9QXIa7kuG9+lSGF+uqMCQBfcpC7ihIDTO9KJt/ni5Y0r2+FT
aYbAT1Vkvv64XRxVcEFiGRv8/v85SNqyX+RfR1OtC6q5HX4TtcExOmGXkWECQQCd
lW3JexJweRcAGDSjV4WtEpFVzH3CugRRHLySAnn5FeismZiKdbPQBbn6i7ML44oj
QaWblJwFsaj2Mqxzbt7tAkB2dxlU+ABHDJ2wvGzECecYPvDeIIcuN1VyZvnYcPek
uehkYsNKd45pNxZr0ZZN1UlVht7kBZWX/+Ij2ezShYDA
-----END RSA PRIVATE KEY-----

しかし、私が望む出力形式は次のとおりです。

-----BEGIN RSA PRIVATE KEY-----
Proc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4Kh+y18X1ZMzWsWBzUV41dD
gLI3CALdrUKZJ8BTSJ0CCxzyD8OX6uwWQVvdoYoLzsM+ndczofch3j5y7fNy9px0
PsS2Q3X+Yq2tqJeVqfkGQtseck9DvMo+4OkCQ0jgEvAKNusIkGG5evWHnto1Fl54
rfuSuHhoanSsMdYmxEVQZnszJfaqr/Bb5d9xCMxvvAFwakip9JZrQNuBSlTiUyw0
rKxvovwRhUlemYX9I+UNJeHpUyQAa4Ky1twfrwZ47vAPreCrQrcAAomkx+QLmxjl
coi48GkWKtbr2mQwhjDoiNWW2F7ZzuX0FVheaay9QlyHlFeDcezxcae44k+eD7jc
FmqH05uQrrlBPQLG5brhqZdhq0skwWwIMeA7yW0oEXmoQ5fyRChgXxiXeYcEblhV
PaBJnVM81Rgrvsys3TdgCHgtUIlJDm+gEp6s8X3yhls8aqXN7R65j9jzXLIzYO40
0tLoistWlRQ5G7MCDgazw/hkIiRaEhSuZZs+e6fa4zyxYYq/UenMpAst7+YyXon2
4nSYd88OEvhpAaoCfQomUdIxjcLsZoheJc19RMv/LHy2stL8ZAFyT62HqOCIhH+A
-----END RSA PRIVATE KEY-----

キーをPKCS#8形式からPKCS#1形式に変換するときに、以下の情報も取得するにはどうすればよいですか?

Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,4D58B420357E8F3A5528539062B3CE0A
5
Vivek Kashyap

暗号化メカニズムを追加するだけです。たとえば、-des3

openssl pkey -in servenc.key -out serv.key -des3
4
Marek Klein
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,E4A3D50AE7D7FF1E

YlFCH5nM36dmGE6cwOMOIQkFz8KXOF4601RgxVz5Jj8D2a2vmb8cin9zvb0oYLhQ
2aJ5cFu29/5MPr6xuVxcD+AA7nbVBHF7mSwc/e4mrQOfwRI3mD7OMRmE8aBp70n9
4jWGfaXgnOio1+sViH0c7fx1greIAyAoyiBvOYiBCZX9BFP5327FN08wmmS/PeuP
IY3AsYyh86PHXCRl6O1/ZKJUhXoG/2gw0JWK02nUNGHQBOQXYbHyVjWvb/s3GbzY
tk6gwY0P6t+dcd/aUo56nbDvm9NT+M9a34/E8chXF5tuYhQoQUyPqGJDvBCp2jOJ
d229Oxy0B9k3RijMA+I/jaEhjrZvTml4WCxf/+C49HEJds3vmRUd9T/j+/YIfO9f
Y7llEawgWByOIafEzupXHuvpm9fva4pz95wo9rogS9GzADfqfnGdoDjCdWFOUcBM
b3glshuBiIOIfS62LuuKgtbTtP44EcwnUq5biC2EhpX9wcYLhSe30KCI2ZqAMeU5
XSncV7SkkKGGgB1CIcOxlPgTr2sXXSMT2nHrGLO9q2BPY8VVvo4Jwp8nqciC8V/n
MFj7ZTzwllqldaN20hYPgSVljRvIPDDNIGvxA9k2woO55+FLxRg2gnsR/gfI0m4I
0c0JWZqm+WNLnzmLGv3lVK4RGLQEsFPL5bI/qwtXwoO55+FLxRg2gnsR/gfI0m4I
lhxMLD4kODP2dF3ZADNXNWbgNlmh9HXmuk6lycxTR69+hwWJfMbtbUeUHR1oQgxQ
EbdCFkccBi4nlqZHIYi5cChDzTtiW+9EFQsQiUDL+zWyWlqkprJcPHrFL58aHhmH
gypdiqw1BpZwjLN7th/QjTWcS8Z712AOKGmcIh4vmvYaLDZouonv3ZqcwXhEE94q
x/GhvRvFnxEbbj/2gzDTEP1oW6jrSQcoFRL/bFBNBAc9oDEyZejndKX8Equht8SV
ariMiZZWT+xDAo+9XfJ7ncGkBsjJmnJgkkl05kIsNw8lcs/3kR3HYxe3pIfFEMm4
-----END RSA PRIVATE KEY-----

上記の種類の暗号化されたRSAキーを、以下の形式でRSAキーに変換しました。

openssl rsa -in consumerencrypted.key -out consumer.key
-----BEGIN RSA PRIVATE KEY-----
MIIJKgIBAAKCAgEA4m6uk9d+D3ceLGY74hcJoSuZgaixhu0j2jn2Y6f5FDaPVxLM
9sdSVXU1xxm24VsMZh078hV/ao02MTguNEvkJ94BaAhfQhyZbUzWhZkzEdFzfE93
WNveNCbzva/wzK9HGvdRpSGrK1vX24C/mCERDfKR/yr0N3lMO0i+EkQHlxprend/
0Kquepeir7B8wd+YA2NNyrGCwF2pMRod9vZXC/h7uugTMjqvfG0C9U9nTxxTXSmz
yqXAI4jq1HrQy9HvO0yA1nyVIpH1JtrUnkQcKUoMHUzz625uNwz+AVb5RqBY+6zi
D8O2t1wfUunCSy4QKHH+zpDf3cZ7AhmKFJHx5+QT6QM24+UdvjlAd5TnYIXXPe/X
u2FUG4bDcaSmnlFiVdcDQsw7IndQnIGxzz3ACJsMtyAhM9LX4H6AjsY2SpOdOfad
/IXufigUQnqVwmeK+JJHu0AOQuTrbNEbIQKCAQEAsuF9scSKlMDHCNUSQCsS++ZW
gWXaJmuOsp5iz+8JJrxPUtGtFAN7ZjwAr9W67DH9LQFT4hNKkkyBkJSLADrcDEzQ
fH4xEHW3K3KMXYfx89iSoHoJ0X1qkRhZHQ2AfwxVFkzBnHcRrYSYGkWqgd4LKcEy
WvMUaWnh+XJASxPXZKW3gPjVENVxiM9T8TPXXRbKAYusy6SUPKMgWWJqxuwxJcYP
lX9lV42t22KIFYLrG/WVgy+IkdyPIez2l2YFkopCywKm/sPA0VYtcu6SlpQJH3HC
1Kgodc4szs60N09q+7wfc5rMq2Sy5sak8osNnqF48d5MIBmUGxIIFigX/V35aA==
-----END RSA PRIVATE KEY-----
0
Lakshmi