Skip to content

Commit

Permalink
Clarification of "public key" and "private key" (php#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Sep 23, 2024
1 parent 62925d2 commit e54c86b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
47 changes: 35 additions & 12 deletions reference/openssl/functions/openssl-pkey-new.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: e50e79746736dbdfbabe9bd3566793b3ddf38f58 Maintainer: duanxiaoqiang Status: ready -->
<!-- EN-Revision: 2e08eac2b22e4cfa97635d5d38b0984b5016a2f3 Maintainer: duanxiaoqiang Status: ready -->
<!-- CREDITS: Luffy -->
<refentry xml:id="function.openssl-pkey-new" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>openssl_pkey_new</refname>
Expand Down Expand Up @@ -40,7 +41,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
成功时返回 <classname>OpenSSLAsymmetricKey</classname> 实例,错误则返回 &false;
成功时此函数会返回 <classname>OpenSSLAsymmetricKey</classname> 的实例;在失败时则会返回 &false;
</para>
</refsect1>

Expand All @@ -64,7 +65,9 @@
</row>
<row>
<entry>7.1.0</entry>
<entry>添加了 <parameter>curve_name</parameter> 配置参数使得可以创建 EC 密钥。</entry>
<entry>
<parameter>options</parameter> 参数中增加了 <literal>curve_name</literal> 键,以便基于椭圆曲线算法创建 EC 密钥。
</entry>
</row>
</tbody>
</tgroup>
Expand All @@ -78,27 +81,47 @@
<programlisting role="php">
<![CDATA[
<?php
$private_key = openssl_pkey_new();
$public_key_pem = openssl_pkey_get_details($private_key)['key'];
echo $public_key_pem;
echo $public_key_pem, PHP_EOL;
$public_key = openssl_pkey_get_public($public_key_pem);
var_dump($public_key);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
// Output prior to PHP 8.0.0; note, the function returns a resource
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArZFsmN2P6rx1Xt7YV95o
gcdlal0k3ryiIhFNzjwtRNNTXfEfBr6lUuaIJYQ8/XqEBX0hpcfuuF6tTRlonA3t
WLME0QFD93YVsAaXcy76YqjjqcRRodIBphAbYyyMI/lXkQAdn7kbAmr7neSOsMYJ
El9Wo4Hl4oG6e52ZnYHyqW9dxh4hX93eupR2TmcCdVf+r9xoHewP0KJYSHt7vDUX
AQlWYcQiWHIadFsmL0orr6mutlXFReoHbesgKY9/3YLOu0JfxflSjIZ2JeL1NTl1
MsmODsUwgAUrwnWKKx+eQUP5g3GnSB3dPkRh9zRVRiLNWbCugyjrf3e6DgQWrW7j
pwIDAQAB
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwknBFEherZe74BiRjTFA
hqwZ1SK7brwq7C/afnLXKhRR7jnrpfM0ypC46q8xz5UZswenZakJ7kd5fls+r4Bv
3P8XsKYLTh2m1GiWQhV1g77cNIN4qNWh70PiDO3fB2446o1LBgToQYuRZS5YQRfJ
rVD0ysgtVcCU9tjaey28HlgApOpYFTaaKPj2MBmEYpMC+kG2HhL12GfpHUi2eiXI
dXT2WskWHWvUrmQ7fJIfI92JlDokV62DH/q1oiedLs9OPNb0rL1aAmYdzaVN6XNH
x/o4Lh125v2vAPV9E3fZCDc/HDEUaahpjanMiCQEgEDp5Hr+CRkvERT5/ydN+p08
5wIDAQAB
-----END PUBLIC KEY-----
resource(5) of type (OpenSSL key)
resource(6) of type (OpenSSL key)
// Output as of PHP 8.0.0; note, the function returns an object
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwknBFEherZe74BiRjTFA
hqwZ1SK7brwq7C/afnLXKhRR7jnrpfM0ypC46q8xz5UZswenZakJ7kd5fls+r4Bv
3P8XsKYLTh2m1GiWQhV1g77cNIN4qNWh70PiDO3fB2446o1LBgToQYuRZS5YQRfJ
rVD0ysgtVcCU9tjaey28HlgApOpYFTaaKPj2MBmEYpMC+kG2HhL12GfpHUi2eiXI
dXT2WskWHWvUrmQ7fJIfI92JlDokV62DH/q1oiedLs9OPNb0rL1aAmYdzaVN6XNH
x/o4Lh125v2vAPV9E3fZCDc/HDEUaahpjanMiCQEgEDp5Hr+CRkvERT5/ydN+p08
5wIDAQAB
-----END PUBLIC KEY-----
object(OpenSSLAsymmetricKey)#2 (0) {
}
]]>
</screen>
</example>
Expand Down
4 changes: 2 additions & 2 deletions reference/openssl/functions/openssl-private-decrypt.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: e50e79746736dbdfbabe9bd3566793b3ddf38f58 Maintainer: mowangjuanzi Status: ready -->
<!-- EN-Revision: 7da0f9995a1a6928523f8d910898e79d88f45d5f Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy -->
<refentry xml:id="function.openssl-private-decrypt" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -48,7 +48,7 @@
<term><parameter>private_key</parameter></term>
<listitem>
<para>
<parameter>private_key</parameter> 必须是跟数据加密相对应的私钥
<parameter>private_key</parameter> 必须是与用于加密数据的公钥对应的私钥
</para>
</listitem>
</varlistentry>
Expand Down
3 changes: 2 additions & 1 deletion reference/openssl/functions/openssl-private-encrypt.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: e50e79746736dbdfbabe9bd3566793b3ddf38f58 Maintainer: duanxiaoqiang Status: ready -->
<!-- EN-Revision: 7da0f9995a1a6928523f8d910898e79d88f45d5f Maintainer: duanxiaoqiang Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<refentry xml:id="function.openssl-private-encrypt" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -48,6 +48,7 @@
<term><parameter>private_key</parameter></term>
<listitem>
<para>
<parameter>private_key</parameter> 必须是与用于解密数据的公钥对应的私钥。
</para>
</listitem>
</varlistentry>
Expand Down
4 changes: 2 additions & 2 deletions reference/openssl/functions/openssl-public-decrypt.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: e50e79746736dbdfbabe9bd3566793b3ddf38f58 Maintainer: duanxiaoqiang Status: ready -->
<!-- EN-Revision: 7da0f9995a1a6928523f8d910898e79d88f45d5f Maintainer: duanxiaoqiang Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<refentry xml:id="function.openssl-public-decrypt" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -47,7 +47,7 @@
<term><parameter>public_key</parameter></term>
<listitem>
<para>
<parameter>public_key</parameter> 必须是和用来加密数据的私钥配对的公钥
<parameter>private_key</parameter> 必须是与用于加密数据的公钥对应的私钥
</para>
</listitem>
</varlistentry>
Expand Down
4 changes: 2 additions & 2 deletions reference/openssl/functions/openssl-public-encrypt.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: e50e79746736dbdfbabe9bd3566793b3ddf38f58 Maintainer: duanxiaoqiang Status: ready -->
<!-- EN-Revision: 7da0f9995a1a6928523f8d910898e79d88f45d5f Maintainer: duanxiaoqiang Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<refentry xml:id="function.openssl-public-encrypt" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -49,7 +49,7 @@
<term><parameter>public_key</parameter></term>
<listitem>
<para>
公钥
<parameter>public_key</parameter> 必须是与用于解密数据的私钥对应的公钥
</para>
</listitem>
</varlistentry>
Expand Down
6 changes: 3 additions & 3 deletions reference/strings/functions/strncmp.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: a3573c18b89fd32aca1c3924d3fd9568900b4a33 Maintainer: daijie Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<!-- EN-Revision: 43cc4ed372bde0a8ee986d57bf522d14099d54a6 Maintainer: daijie Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<refentry xml:id="function.strncmp" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>strncmp</refname>
Expand Down Expand Up @@ -94,7 +94,7 @@
$var1 = 'Hello John';
$var2 = 'Hello Doe';
if (strncmp($var1, $var2, 5) === 0) {
echo 'First 5 characters of $var1 and $var2 are equals in a case-sensitive string comparison';
echo 'First 5 characters of $var1 and $var2 are equal in a case-sensitive string comparison';
}
?>
]]>
Expand Down

0 comments on commit e54c86b

Please sign in to comment.