Decrypting private key in ColdFusion

I’m following these instructions and I am struggling to decrypt the private key in ColdFusion/Lucee.

Here’s how it’s done in PHP:

$private_key = $config->boxAppSettings->appAuth->privateKey;
$passphrase = $config->boxAppSettings->appAuth->passphrase;
$key = openssl_pkey_get_private($private_key, $passphrase);

Has anyone managed to get it working?

I’ve skipped this step for the time-being and decrypted the private key in Terminal instead, but I’d be interested to know if anyone has got this working in ColdFusion/Lucee.

Hi @patientnut , welcome to the forum.

I’m not familiar with Lucee, so I don’t know what it provides in terms of private key decryption. I’ve tried to do the same using javascript and struggled to find a library that would offer that out of the box.

You found the workaround though.

Let’s see if other members working with ColdFusion/Lucee respond.

Cheers

Hi
I have been trying to decrypt the Box Private Key in Windows Terminal but did not succeed.
Could you please provide a step-by-step instruction for dummies that includes everything I need to do ?
I am not a developer so please leave nothing out :wink:
I would really appreciate you help as I have been struggling with this for quite some time now.
Cheers

This is how it’s done on Mac, so you’ll need to find the Windows equivalent.

  1. Copy the privateKey from config.json and paste it into a new encrypted_private.key file.
  2. Replace all occurrences of \n with new lines.
  3. In Terminal, run openssl rsa -in encrypted_private.key -out decrypted_private.key.

This decrypts the private key and stores it in decrypted_private.key.

Thanks for getting back to me !!

I have created the following file : BOX_encrypted_private_key.key
The file looks like this:

I then open Terminal and tried different ways as picture below shows.
But I keep getting errors as shown in picture.

I have also tried to put the location in command in Terminal, like this :
openssl rsa -in C:\Users\xxx.yyy\Downloads\BOX_encrypted_private_key.key -out C:\Users\xxx.yyy\Downloads\BOX_de_encrypted_private_key.key

But I still get the same erros in Terminal.

Can you tell me what is wrong ?

Forgot to mention that Box documentation on this URL : https://developer.box.com/guides/authentication/jwt/without-sdk/#2-decrypt-private-key

Explains that I need a passcode to unlock the encrypted file. I do have the passcode for this but don´t know where to put it in Terminal ?

Hi @laa ,

Looks like openssl is not installed or not in the path of your windows…

Thanks for your reply.
I had issues with openSSL and now changed to use Client and Secret for getting my Access Token.
Application now works as expected :wink: