You put this in your terminal
openssl genrsa -out http_auth_key.pem 2048
then " Take the base64 string, and make it into 1 line. That string is value to set APIKeyPrivateKey to."
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Uh, hopefully more experienced people can take a look at this, https://github.com/chc/thps.api#generating-an-api-key about generating my API key but I don't think it's hitting home for me, like, where do I need to put:
openssl genrsa -out http_auth_key.pem 2048
You put this in your terminal
openssl genrsa -out http_auth_key.pem 2048
then " Take the base64 string, and make it into 1 line. That string is value to set APIKeyPrivateKey to."
I was reading into this: https://www.openssl.org/docs/manmaster/man1/openssl-genrsa.html I didn't know it.. ah okay so just take the base64 string into my Laravel controller and make it have that value.
I get something like this: ....................................................+++ Im confused.
Yeah, I'd put it in the ENV and map it to config vars. Usually, the only time I had to deal with keys, was when I was required to "SIGN" the responses I returned. I don't understand the reason or the needs from what I saw on the repo you mentioned above. (I'd be glad if somebody explains)
Okay. Does using something like this: https://onlinestringtools.com/convert-string-to-base64 is needed?? it gives me "stuff", am I supposed to do that? or literally as you mentioned, copying and pasting that sequence of dots..
cat http_auth_key.pem <- Shouldn't show you .....
Sorry I am lost.
openssl genrsa -out http_auth_key.pem 2048
This command generates a private RSA key and stores it as http_auth_key.pem . if you view the contents of http_auth_key.pem (you would not see the ....++) you saw in the terminal, but the something like
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA1y3WNCwyxRHVqczkrYdAqaHJaPk4YwPJUrCZpfBCQIZ82gbe
TlUSM5c1JRlrENlWpV+K0wZnSn3+xjDakZY2Cb92WKBx69YapxxFV0tubzsB7Kxv
/ztPR0p9eISjvmo4vLsksKEHx1EOcw6OZ2GGq8HoHqiK9BxPWuqn2dfcp6v4hwVH
inndM43qHS+xKP/2dcKc+1SP4B2bMptqU/pBYVD3/3EyGQsOwqaFt1cVkXsyRyf1
8pKUEJT2xJlf8OXjg3VkUotuJWksJhHObexBbHNZgFyndsENasT0ovyfJYobjReS
u9O51oj4hwjWm3tFrX/fUW24UqFvKiscjcNSgwIDAQABAoIBAAyscnVYNRVOW5tI
qh9eW/yhvs8j/qI2UuE/7YzMfdp3EVt2FBnhANVxDnxE5v1zD5tl6TNMqUDF8v+R
WQ5CHqSsVjgaGxuc3K0DCUJ++t4qR469CUurHpxAUuuKRGqurvDOxPZyRZcDuyoj
rVeBcwEixp0nqCeAk1vzfjdic2icqLbOJI1P/sfUYPBht57urxCgvH0sqKukDXVS
XFKocGOb6IjjLeRfqIiX576SCCXB8XIwmGLziHyLWGVLZCFOyW8+O615UGfvYKsq
CeTAsh886X7a60k0UsLzOEvz2Nmk48hte4Rc8QqIQBpW5T97a7yRBvySfNtrUDR1
GRRYiWECgYEA9KKUmsAZEeyh8XL97ax3cfMLzUeesSkso4hDh+3nWskZ7Tgm5ZbW
-----END RSA PRIVATE KEY-----
You need to take the contents of the http_auth_key.pem and encode them in base64 . That is my understanding of the instructions.
How do I encode it to base64 string? I get a similar result when doing what you just mentioned, thanks!
see below
I'm giving you the encode/decode base64 helper functions I use below, if you run into trouble with the normal ones. (just in case)
function base64url_encode($data)
{
$b64 = base64_encode($data);
if ($b64 === false) {
return false;
}
$url = strtr($b64, '+/', '-_');
return rtrim($url, '=');
}
function base64url_decode($data, $strict = false)
{
$b64 = strtr($data, '-_', '+/');
return base64_decode($b64, $strict);
}
Thanks for your help!
Glad I could help :)
Where should I put this? Is this like the "configuration file" to use the API key on my Laravel environment?
well yes - i'd do the following : in your .env file
//.env file
MY_COOL_ENV_NAME="THELONGAPIKEY"
then in the config directory I'd create a file "myapiconfig.php" which would be like this
<?php
return [
'api_secret_key' => env('MY_COOL_ENV_NAME'),
];
Then anywhere in my app where I need that key I could access it like this :
config('myapiconfig.api_secret_key');
I see, could this be a global config, config('myapiconfig.api_secret_key'); so I wouldn't need to specify it on various views or controllers and whatnot...
Well it could be anything its up to you, but generally - you wouldn't want to show your secret api key in views and controllers (well depends on your use-case). If you are using it to make calls to as service I'd create a class for that service and only it would know about its api_key (so that config(xxx.xxx) is in one place - where you need it). Then make the instance of that class global or call it whenever you want and do your thing (just an idea i don't know your usecase)
@warpig did you sort it out ?
No
what is the issue you’re having
@teos_97 The repo offers the GUI but the problem is that it used Vue which im not too familiar, I can always learn it, no problem. I will try again with Laravel, I don't mind starting the design from scratch.
@teos_97 I went through our conversation and i just finished placing :
config('myapiconfig.api_secret_key');
in my welcome.blade.php, is that fine? I've no idea yet how to see if it's working...
EDIT: Tested and doesn't seem to be working, alright this is what i've done:
<?php
return [
'api_secret_key' => env('THPS_API'),
];
config('myapiconfig.api_secret_key');
:-D !
If you want to check that config('myapiconfig.api_secret_key'); has the right value just run php artisan tinker and call config('myapiconfig.api_secret_key'); there. It should return the value that you have given THPS_API in your .env.
I am not sure what is this application or what its usage / purpose but have a look at this : https://github.com/chc/thps.api/blob/master/THPS.API/appsettings.json The Private Key is set there - I hope you don't mind me asking but is this back-end what you need or is it something similar you want to build with laravel ? Im' confused what is the end goal ?
I hadn't look at that myself so perhaps it was made with Vue in mind, hmm.. this project is solely recreational and it's not a back-end database or service, to be honest I don't understand why I need an API, I just wanted to redesign the "official" website, http://save-editor.thmods.com/#/manage_save its more like an online-tool created for a PC video game where it can read it's save files edit them and then export them back, but like I said I don't even know why I'd need an API for that, perhaps to access the "online version of the save editor"?
Please or to participate in this conversation.