使用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?

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.