可以使用 PHP 中的内置函数 openssl_pkey_new 生成一个 ED25519 密钥对吗?

huangapple go评论61阅读模式
英文:

Is it possible to generate an ED25519 keypair with the built-in openssl_pkey_new function in PHP?

问题

我试图在PHP中使用内置的openssl_pkey_new生成一个ED25519私钥/公钥对,但我无法让它工作。

不确定,但这可能不可行吗?

使用PHP-7.3.13和OpenSSL-1.1.1d。

// OpenSSL配置
$openssl_config = array(
   'curve_name' => 'ed25519', // <- 无法工作
   'private_key_type' => OPENSSL_KEYTYPE_EC
);

// 创建OpenSSL密钥对
$openssl_keypair = openssl_pkey_new($openssl_config);
openssl_pkey_export($openssl_keypair, $privatekey);
$openssl_details = openssl_pkey_get_details($openssl_keypair);
$publickey = $openssl_details['key'];

echo $privatekey;

echo $publickey;
英文:

I'm trying to generate an ED25519 private/public keypair with the built-in openssl_pkey_new in PHP, but i don't get it working.

Not sure, but isn't it possible?

Using PHP-7.3.13 and OpenSSL-1.1.1d.

&lt;?php
...

// OpenSSL config
$openssl_config = array(
&#39;curve_name&#39; =&gt; &#39;ed25519&#39;, // &lt;- not working
&#39;private_key_type&#39; =&gt; OPENSSL_KEYTYPE_EC
);

// Create OpenSSL keypair
$openssl_keypair = openssl_pkey_new($openssl_config);
openssl_pkey_export($openssl_keypair, $privatekey);
$openssl_details = openssl_pkey_get_details($openssl_keypair);
$publickey = $openssl_details[&#39;key&#39;];

echo $privatekey;

echo $publickey;

...
?&gt;

答案1

得分: 2

以下是翻译好的部分:

看起来不可能,在 https://www.php.net/manual/en/function.openssl-get-curve-names.php 上阅读文档,没有ED25519曲线名称。

ED25519用于签名,因此要在PHP中生成一个ED25519密钥对,请使用'sodium_crypto_sign_keypair'函数。

英文:

Looks like impossible, read doc on https://www.php.net/manual/en/function.openssl-get-curve-names.php, there is no ED25519 curve name.

ED25519 is used for signing, so to generate an ED25519 key pair in php.
use 'sodium_crypto_sign_keypair' function.

huangapple
  • 本文由 发表于 2020年1月4日 00:22:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581924.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定