douhu8851 2017-09-04 12:20
浏览 112

使用Open SSL生成公钥和私钥

Generating public and private keys with openssl. However the code generates a very long keys and these can't be used in authenticating an API.

$config = array(
    "digest_alg" => "sha512",
    "private_key_bits" => 4096,
    "private_key_type" => OPENSSL_KEYTYPE_RSA,
);

$res = openssl_pkey_new($config);

openssl_pkey_export($res, $privKey);

print_r($privKey);

$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];

print_r($pubKey);

Is there a way to generate a 60 char private key? And a 20 char public key which are unique with this technique?

  • 写回答

1条回答 默认 最新

  • dpq39825 2017-09-04 12:53
    关注

    Not with RSA in OpenSSL. Even the lowest bit count of 32 results in a 64 byte private key. Security is also bad with short keys and should be avoided.

    Maybe you could implement a token request call with using a long secure key and then use the smaller token for further requests. This limits the data overhead overall. That needs more coding to be done but may be a way to go.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作