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

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

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。

  1. // OpenSSL配置
  2. $openssl_config = array(
  3. 'curve_name' => 'ed25519', // <- 无法工作
  4. 'private_key_type' => OPENSSL_KEYTYPE_EC
  5. );
  6. // 创建OpenSSL密钥对
  7. $openssl_keypair = openssl_pkey_new($openssl_config);
  8. openssl_pkey_export($openssl_keypair, $privatekey);
  9. $openssl_details = openssl_pkey_get_details($openssl_keypair);
  10. $publickey = $openssl_details['key'];
  11. echo $privatekey;
  12. 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.

  1. &lt;?php
  2. ...
  3. // OpenSSL config
  4. $openssl_config = array(
  5. &#39;curve_name&#39; =&gt; &#39;ed25519&#39;, // &lt;- not working
  6. &#39;private_key_type&#39; =&gt; OPENSSL_KEYTYPE_EC
  7. );
  8. // Create OpenSSL keypair
  9. $openssl_keypair = openssl_pkey_new($openssl_config);
  10. openssl_pkey_export($openssl_keypair, $privatekey);
  11. $openssl_details = openssl_pkey_get_details($openssl_keypair);
  12. $publickey = $openssl_details[&#39;key&#39;];
  13. echo $privatekey;
  14. echo $publickey;
  15. ...
  16. ?&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:

确定