从openssl_pkey_get_private()检索原始私有密钥

时间:2021-08-13 18:28:47

I've been spending quite some time trying to figure out how exactly to retrieve the raw private key data from openssl_pkey_get_private() using a passphrase. I feel like there's a simple thing I am missing.

我花了相当多的时间试图弄清楚如何使用passphrase从openssl_pkey_get_private()中检索原始私有密钥数据。我觉得我错过了一个简单的东西。

Here's my code:

这是我的代码:

$config = array(
    "private_key_bits" => 2048, //size of private key
)

$privKey = openssl_pkey_new($config); //creating a private key resource
openssl_pkey_export($privKey, $pkeyout,"test123",$config); //obtaining an encrypted private key
$result = openssl_pkey_get_private($pkeyout, "test123"); //decrypting the encrypted private key
var_dump($result); //print results

Unfortunately all I'm getting from the var_dump() call is the following output: "resource(2) of type (OpenSSL key)"

不幸的是,我从var_dump()调用中得到的是以下输出:“资源(2)类型(OpenSSL密钥)”


So, pretty much after I call openssl_pkey_export, $pkeyout contains something like the following - consider the below data the INPUT for the decryption procedure I wish for openssl_pkey_get_private to perform:

因此,在我调用openssl_pkey_export之后,$pkeyout就包含了如下内容—考虑下面的数据,即我希望openssl_pkey_get_private执行的解密过程的输入:

-----BEGIN RSA PRIVATE KEY-----

- - - - - - - - - - -开始RSA私钥

Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,84AC553B6367CD10 BOVayTi4R9IZX0V1/lbX/YG16v87vQ1AX5apgcPEwOaJDRBUB07iiJwkSEOckR3w yW/2E27YXhJGaVjSMiBbBycu9AHQIgNhggUCXvzr6AMhDYNAu787c0EUsA7Ax4Yw Gixk9qX/iECcjVXqdoz2+pSrRUUB5l3T+JyRh8sgKkdcM74dEQ5UDTrMd1Ik26+N 4Ms8iA9SS9J1FdTBswx119+WTcybSCBsX0tWPkjf7SARzgL9ee02B61Mua2PypZy RO4UIRGeQy/0O/ySdUg1L42sTmmwY7odWnwbbYsIgFsSaijDGx14VohgnRbEZK++ 6Ix0w1ZYSzsKWiZEEuXXC6EvOIv6zOiUmJRW/0jGjuDIbz0MTtYgU/A99fK97EYo /xWNIm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QfQs0AUrxlAe75Sh9zoV4FKpq4A7JM31zklVjJw3rqjxBmNIBUow586 4WPFsIgGJQ0Gp3PfoO4sl/BuIxVjhe31yYAaeK+jA5K48PCPgirE/nck/08cxZdZ

加密DEK-Info Proc-Type:4:mso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font: minor - bidi ' > < / span > < spanmso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font: minor - bidi ' > < / span > < / span > < / p >这是一种常用的方法,我们可以用它来表示,我们可以用它来表示,我们可以用它来表示,我们可以用它来表示。tcI9dKbHUOj42ZrtWYZhR + K8XwrxEg8u4kkQv2U13bySBihx / WSuZURXSjULyI2h nd8wQddVPFGodxd8CTT / 3 gpp97odc16i3ynj7apkjxrjxl8hvziye3yahnf39dag JWbC1roUcQfQs0AUrxlAe75Sh9zoV4FKpq4A7JM31zklVjJw3rqjxBmNIBUow586 4 wpfsiggjq0gp3pfoo4sl / BuIxVjhe31yYAaeK + jA5K48PCPgirE / nck / 08 cxzdz

-----END RSA PRIVATE KEY---

推荐- - - - - - - - - - -端RSA私钥

What I really want is the raw, decrypted private key (the supposed OUTPUT of openssl_pkey_get_private(). Notice that the above is encrypted** (as denoted by the word 'ENCRYPTED' under "-----BEGIN RSA PRIVATE KEY-----").

我真正想要的是原始的、解密的私钥(openssl_pkey_get_private()的假定输出)。请注意,上面的内容是加密的**(由“----- -----开始RSA私钥----- ----”

This would look something like the following (notice that the data below does NOT have the header stating that it's encrypted as the data above does).

这看起来类似于下面的内容(注意下面的数据没有标题声明它是加密的,正如上面的数据所做的那样)。

-----BEGIN RSA PRIVATE KEY-----

- - - - - - - - - - -开始RSA私钥

MIIEowIBAAKCAQEAzuhc4J08EiayUSpIQ9MG6FM5JwYm1d0UIaAZ9h2QV4r897Oo GxvxaQ/ceIY7Sdrpc6kWAF+cemKfA84WX6T+LgiimfZnSIDhF1xHFk2Yluc8cyqq gKswgewZi01dVz4nP+1w/kPUNv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CMiPitH0Q0N6UkgwKBgQCktsHJ48zCKGu8X3I11DAxYy6kl1mPgt3Zhwpm o+cMb2B2QEFsGLar0vxztA6IUUQnZp4YolAmSBX6Y0qLXgyFUDzcvxygKABmHcCV rogsUatkUcvUCSFa41xx21A8OxKTLz2iRHEhsKo3aR1FQW4nowTIlv0RIrXqnZ8F aWr5pwKBgGngeK3PyoXvOZNZ5f9r3i4C3d7UHz9Aiwn2Ulh138dp1AW8d4a9AiTZ RBd9pQGsIsSzhPkTZ65Mx+R6X+v/xfnFjnShronfeNdkpkgACbgQvJTDbg8Asu9x ifwaEKu8+t1MqrmPh5vKY6Fhl2DdPkk2evp6eG1t1IO6pAkYb8L5

这是一种很好的方法,它是一种很好的方法,它是一种很好的方法,它是一种很好的方法,它可以帮助我们提高它的质量。这是一种很好的方法,它是一种新型的方法,它是一种新型的方法,它可以使我们的产品在生产过程中得到更好的应用。这是一种很好的方法,它是一种非常有效的方法,它是一种非常有效的方法,它是一种非常有效的方法,它可以使我们的产品在不同的环境中得到更好的应用。rogsUatkUcvUCSFa41xx21A8OxKTLz2iRHEhsKo3aR1FQW4nowTIlv0RIrXqnZ8F aWr5pwKBgGngeK3PyoXvOZNZ5f9r3i4C3d7UHz9Aiwn2Ulh138dp1AW8d4a9AiTZ RBd9pQGsIsSzhPkTZ65Mx + R6X + v / xfnFjnShronfeNdkpkgACbgQvJTDbg8Asu9x ifwaEKu8 + t1MqrmPh5vKY6Fhl2DdPkk2evp6eG1t1IO6pAkYb8L5

-----END RSA PRIVATE KEY-----

- - - - - - - - - - -端RSA私钥


All in all, I guess what I'm trying to say is that I don't know how to retrieve the decrypted private key that openssl_pkey_get_private() is supposed to return. It's not returning FALSE, so it must be working... I just don't know where it puts it.

总之,我想说的是,我不知道如何检索openssl_pkey_get_private()应该返回的解密的私钥。它不会返回FALSE,所以它必须工作…我只是不知道它放在哪里。

Any help would be greatly appreciated as I am very stuck!

当我被困住的时候,任何帮助都将得到极大的感谢!

Thanks a lot!

谢谢!

1 个解决方案

#1


2  

I hope this is what you're after.

我希望这是你想要的。

$privKey = openssl_pkey_new($config); //retrieve priv key resource
openssl_pkey_export($privKey, $pkeyout); //obtained unencrypted private key.
var_dump($pkeyout); //print results

The newly generated key does not have a passphrase yet, so you can get the unencrypted key straight away.

新生成的密钥还没有密码,因此您可以直接获取未加密密钥。

Edit

编辑

Based on the comment, I generated my own keypair with

基于此评论,我生成了自己的密钥对。

openssl genrsa -des3 -out privkey.pem 2048

I was then able to dump out the unencrypted private key with the following:

然后我可以将未加密的私钥转储为:

$r = openssl_pkey_get_private('file://privkey.pem', 'temp123');
openssl_pkey_export($r, $pkeyout);
var_dump($pkeyout);

You can supply the key instead of the filename, as long as it is PEM formatted.

您可以提供密钥而不是文件名,只要它是PEM格式的。

Edit 2

编辑2

I couldn't get your supplied key working with the passphrase you included in the question, but it does work with the temporary key I generated.

我无法让您提供的密钥与您在问题中包含的密码一起工作,但是它使用了我生成的临时密钥。

The exact code I am using is as follows:

我使用的确切代码如下:

$k = <<<EOF
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,878E66CD01D1A379

RIAnkFVcUEfLXqopP/ywpF0yeYWE2LijOmWuGBRgXup/cIA42jrXuRF+WBR5Ni+2
8IWnbiMh9tseTYpAcAp32JeCvlNqes65qEh93qVLKU6K4uYg/rh170hdrUd6DL7R
mLrXWm3ciBCatxancok6uJcP1FksWrdjpR8z9thKAGXWOIVxvudBgK0Fpf/FtmJA
A5x84Zb8FiN+cyJyvYrQm89v9Une+7kA7x6T8Q/QSDvG1ik5efJAFg2vBqo6Jlht
nJjwDQKtTn7tpUANY7Y/aMoEllkEPOM4MFc3r9g59rGq16BTbhBMmI3TUkg0p2nx
tIOq1N568RYh8OVGtaHu5HJ0W7LKmtqhgvSj70i+ed4wOJotQ+OXCfS6SWQKrS4o
jLFNuH6K7uzO4GGnacSupFtyO29UiCYmV0LQpLCg599ffjuHI+iFBj1JeRrE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2sS7dMG0erHlVzN+kKSC8CGEVgHMNpyjWdFT7rwksC4s85c
iJ/BIYymy2sCpr/YnzT2blE1hFCrLbyc1FuBh+SDr9jtnVvErndlMg==
-----END RSA PRIVATE KEY-----
EOF;

$r = openssl_pkey_get_private($k, 'temp123');
openssl_pkey_export($r, $pkeyout);
var_dump($pkeyout);

And the output is:

和输出是:

string(1675) "-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtAOvzSslm7QPNRRZgHC9zAbl/f1U1Ni5vmHqazmNaSvM+Wwq
ZbbeFtBfnSB13Q9aBt7oEFjaS7yhmBcdy9/JkzO7eOpxQOFNaHpXf8a95Qlhpt7x
S++4VXzX2RB2ja0xBLacggXz6puRaaH4zwsxTKzeyzdfochovpj1JMRNHJYj5Hi7
EJy3gxL6Lmi5PMir0cu/J86Ls0tcRMJjSdtWH9Ut9TQNhn6wyrHm4mM7SL+j5eBZ
mZlRRAb/Is3r+/mn23UNUEMcVpi7FHi2jgVwrEToWZugWcdQOnQFBkAFSaEZFvO9
OmctbiNZY1ZvB3mDyZIzVGHBpdPNNaYpZg3q2QIDAQABAoIBAD6E3USrTId0FKgB
pkf2X+SBLNV2a0T09CWLyidtOJCjNrAVgfALf7x6qAphIK4iy8iBGCW9RitxmsnA
lYed9FscZ2rKOYUn+oNjogntkzv9cx3KZhFSczm1fx2TGyl/UfvqFBcQTDNZzjna
mBgIMhoIG+SGGb+NY9t2MgWP65wWb6vJgQTw7NeaZguA6gGfvsdI/VSv2xHvHe2Q
MiVIQxfBoOPOs9mCOJJMSsfDogo0JE7MehV+D2mx5ZA3uJLN+0cvvYO48SvdJwXB
fp3lmT+XbXSDJ/KB/AxgONgl3lb4clr46pXkdWWBfwTMJmOGcLLvaBjniZGUBOeW
3v8RWoECgYEA313cXyxc2WWJiaXJqnPC/+L9AVpYZYJZEt2T8D4uffJJUe61k3Vu
G4UlGaeCpRakfWr7QuKyPOsWyDsXrTXivftGnlflFGAiAV+ssfs1YdjnwHWIJ3Xg
fSyVPyQCZprDtCzrHKlUCYh4uyuUP9X9B6iSdFCDczLEYb8hIPgu9dECgYEAzlBo
dG2f7u93FoLlmzxPU2HnZlu/xtyCwo0phr7Z+cX+2D3KWAHnEYDtE+hOX7cxg/UF
RMLkApFz3H962bu5eFIsMtkd/XigD4ByNxSr9rKxsKisEg9UCnFwiR8jCXeCCjYP
/OjFAH2yk0J2zYOa091sin94G6qjSGAyPwNX/okCgYEAo0rz+yPscQXY6aco6hKd
AQLJYb7RlswXIEKaj2x2Ap8o2NwBJF8Z8saAm+OpD9WgxQt7yqb+FKjsy87ffUJC
lA7pzoKFN0McORLfpnH20aSHsFx8ABUd24THSxShKK+F2Odprldf12RMltDCHXTr
+ThUcPIXVxVLGgZnSroFYrECgYA+x0zhkLIH3KoaGX6QfAuPTc1B4k06z8KiPJ4U
OGLPlCX12ueFXB7ZvqdlVVzz1ySkCJyvzbXf6i6dO9VAB9Vp/Wchmdt8U4Yw8V7P
z+R7zugu30RswmlKPDaIIwdgTBMv1D+NL68ydQ0vrhvEcXVdXpU2l48OrB+/WDYx
4myWMQKBgGFVuEOb4yKHTeQo5R/+gRsyrDIE0Xzq5t3WZjssjeju5q5c6Fp24qDb
jq8SNkLXOMsATc9iLnYKeZa2EXR2w548LmY2L+TGk/XT2eZrFY0NImaDIPwS7KFq
keO8GceLlhXU3wgDSb6NWkuCxDJrYJqhGVFHmuI7/Ntll2o4eVuD
-----END RSA PRIVATE KEY-----
"

#1


2  

I hope this is what you're after.

我希望这是你想要的。

$privKey = openssl_pkey_new($config); //retrieve priv key resource
openssl_pkey_export($privKey, $pkeyout); //obtained unencrypted private key.
var_dump($pkeyout); //print results

The newly generated key does not have a passphrase yet, so you can get the unencrypted key straight away.

新生成的密钥还没有密码,因此您可以直接获取未加密密钥。

Edit

编辑

Based on the comment, I generated my own keypair with

基于此评论,我生成了自己的密钥对。

openssl genrsa -des3 -out privkey.pem 2048

I was then able to dump out the unencrypted private key with the following:

然后我可以将未加密的私钥转储为:

$r = openssl_pkey_get_private('file://privkey.pem', 'temp123');
openssl_pkey_export($r, $pkeyout);
var_dump($pkeyout);

You can supply the key instead of the filename, as long as it is PEM formatted.

您可以提供密钥而不是文件名,只要它是PEM格式的。

Edit 2

编辑2

I couldn't get your supplied key working with the passphrase you included in the question, but it does work with the temporary key I generated.

我无法让您提供的密钥与您在问题中包含的密码一起工作,但是它使用了我生成的临时密钥。

The exact code I am using is as follows:

我使用的确切代码如下:

$k = <<<EOF
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,878E66CD01D1A379

RIAnkFVcUEfLXqopP/ywpF0yeYWE2LijOmWuGBRgXup/cIA42jrXuRF+WBR5Ni+2
8IWnbiMh9tseTYpAcAp32JeCvlNqes65qEh93qVLKU6K4uYg/rh170hdrUd6DL7R
mLrXWm3ciBCatxancok6uJcP1FksWrdjpR8z9thKAGXWOIVxvudBgK0Fpf/FtmJA
A5x84Zb8FiN+cyJyvYrQm89v9Une+7kA7x6T8Q/QSDvG1ik5efJAFg2vBqo6Jlht
nJjwDQKtTn7tpUANY7Y/aMoEllkEPOM4MFc3r9g59rGq16BTbhBMmI3TUkg0p2nx
tIOq1N568RYh8OVGtaHu5HJ0W7LKmtqhgvSj70i+ed4wOJotQ+OXCfS6SWQKrS4o
jLFNuH6K7uzO4GGnacSupFtyO29UiCYmV0LQpLCg599ffjuHI+iFBj1JeRrEDc4W
z+6jc4gnLdgAJVoTUD0skx3VinXrjf5q5/ctZOOWCHSFV3BeuatfuGj8w/oKM9Y2
ppYcI5uyA07+a0mVmSvpJIJMcAf8FlIRf3HfTkjkyaCD8h1SbDtaBSdlkKRZHqUX
f7jSe58MqwYZiLRcX0mYxZfv9oVDzT4AgIiTwFF33zQriBSer/TI57WLV+PZ3j9y
lolXdK6pkAPkMnJSbpcf0RcXvDrY646J5pxgylGgn/A1mgD1btmJSVBbcb75Wy3e
Heir6+VaQ/V/j8U9nZfNkGqnEv3TwGhj8u010tgeG/lfxA3eQMw04WlRac37GlRr
IrEbpOW88JZIknvY1w8/c+uzGDIRL8ucUkL1s5j626Z8UxN7KTuuXaWNdenPGzx/
pgAwNlkhS+f4uUajYDEbgy7o1v7L1K0xRDglqTTXmycr82mMTNZR0r/KRt7dlDI1
ZM/7BIT0iRsm+16ZBF/R9i0S3uu4ox87cBfaIOlo9h73tYM/6RMJ0NfsPJtSzzM+
dRZRuyNImA8PDQG2yTmIhOmDQbnzywBsNfWfFX+8SJtAHPnENMvdwkWrDgaVSvPK
K4PzRLqKG3oU9CdXk+y2fFxumFeMUbupLh/AgQWiVsEdA1Igz7jQ2iIrC8BB0Jy6
igOMn9Db/o/fJ4QMe0IIdw4ZIqhVt0IIt50ElZHd8ASLpQxhggXtafpcO/fn0Rpx
ZJ7hWff9hIGbGQtf5i3fy8RUjUpplPYkleQCQls6Dss5c31vTX4evEAWzfKLe0eA
Cuq1uTJ8aB13cRbcHTmR0i8GLiE/93U2oB+hPVCeZEWtPAaqOyVIsU8uD7/2xNa2
C73gtJ3N3Kr8SR5QSB3aRZEA1uxAbtvNRUl9Vo8ECw+S2l0iGmrzXtVY1+4sGu9K
57+kobM58y1eNuwyCuv8uryCoA2CdMBGwKZn2XgLPda7RBIfY52u7R/oM3Pm2JbT
iVL2PxeTCSuH/Z3FKbRdTQ/0+IvR/Xd70rnTTkQD6TdMa53UEg3xnftOfZr9JrWw
/mYvYAQdgwARddTlG2sS7dMG0erHlVzN+kKSC8CGEVgHMNpyjWdFT7rwksC4s85c
iJ/BIYymy2sCpr/YnzT2blE1hFCrLbyc1FuBh+SDr9jtnVvErndlMg==
-----END RSA PRIVATE KEY-----
EOF;

$r = openssl_pkey_get_private($k, 'temp123');
openssl_pkey_export($r, $pkeyout);
var_dump($pkeyout);

And the output is:

和输出是:

string(1675) "-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtAOvzSslm7QPNRRZgHC9zAbl/f1U1Ni5vmHqazmNaSvM+Wwq
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